Where and how not to double post
I am running the whole function on Ontrade but as it is not working that is why i have userd OnTick .
but I am unable to get history it shows history deals and orders as 0
void OnStart() { Print("history-->", HistoryDealsTotal()); }
HistoryDealsTotal
Returns the number of deal in history. Prior to calling HistoryDealsTotal(), first it is necessary to receive the history of deals and orders using the HistorySelect() or HistorySelectByPosition() function.
You need to select the deals first.
thanks for resolving I got the information of history deals and orders and here is the data I got for one trade -
{ "o_ticket": -265476697, "o_time_setup": "2024.02.19 14:17:51", "o_type": "ORDER_TYPE_SELL", "o_state": "ORDER_STATE_FILLED", "o_time_expiration": "1970.01.01 00:00:00", "o_time_done": "2024.02.19 14:17:51", "o_time_setup_msc": -1044711995, "o_time_done_msc": -1044711995, "o_type_filling": "ORDER_FILLING_FOK", "o_type_time": "1970.01.01 00:00:00", "o_magic": 0, "o_reason": "ORDER_REASON_CLIENT", "o_position_id": -265479043, "o_position_by_id": 0, "o_volume_initial": 0.03000, "o_volume_current": 0.00000, "o_open_price": 0.61378, "o_sl": 0.00000, "o_tp": 0.00000, "o_price_current": 0.61378, "o_price_stoplimit": 0.00000, "o_symbol": "NZDUSD", "o_comment": "", "o_extarnal_id": "", "digits": 5, "deal_ticket": -264702106, "deal_order": -265476697, "deal_time": "2024.02.19 14:17:51", "deal_time_msc": -1044711995, "deal_type": "DEAL_TYPE_SELL", "deal_entry": "DEAL_ENTRY_OUT", "deal_magic": 0, "deal_reason": "DEAL_REASON_CLIENT", "deal_position_id": -265479043, "deal_volume": 0.03, "deal_price": 0.61378, "deal_commission": 0.00000, "deal_swap": 0.00000, "deal_profit": -0.15000, "deal_symbol": "NZDUSD", "deal_comment": "", "deal_external_id": "", "deal_digits": 5 }
Here I have a confusion Any one can please tell me what is the closing time of the particular trade because I have the entry time but not exit so still my issue to get closing time is not resolved.
Hi ,
thanks for resolving I got the information of history deals and orders and here is the data I got for one trade -
Here I have a confusion Any one can please tell me what is the closing time of the particular trade because I have the entry time but not exit so still my issue to get closing time is not resolved.
string RequestTradeHistory() { //--- request trade history string content = "{"; long o_time_done ; HistorySelect(from_date,to_date); uint total_deals=HistoryDealsTotal(); ulong ticket_history_deal=0; //--- for all deals\ content += "\"Deals\":"; for(uint i=0; i<total_deals; i++) { //--- try to get deals ticket_history_deal if((ticket_history_deal=HistoryDealGetTicket(i))>0) { long deal_ticket =HistoryDealGetInteger(ticket_history_deal,DEAL_TICKET); long deal_order =HistoryDealGetInteger(ticket_history_deal,DEAL_ORDER); long deal_time =HistoryDealGetInteger(ticket_history_deal,DEAL_TIME); long deal_time_msc =HistoryDealGetInteger(ticket_history_deal,DEAL_TIME_MSC); long deal_type =HistoryDealGetInteger(ticket_history_deal,DEAL_TYPE); long deal_entry =HistoryDealGetInteger(ticket_history_deal,DEAL_ENTRY); long deal_magic =HistoryDealGetInteger(ticket_history_deal,DEAL_MAGIC); long deal_reason =HistoryDealGetInteger(ticket_history_deal,DEAL_REASON); long deal_position_id =HistoryDealGetInteger(ticket_history_deal,DEAL_POSITION_ID); double deal_volume =HistoryDealGetDouble(ticket_history_deal,DEAL_VOLUME); double deal_price =HistoryDealGetDouble(ticket_history_deal,DEAL_PRICE); double deal_commission =HistoryDealGetDouble(ticket_history_deal,DEAL_COMMISSION); double deal_swap =HistoryDealGetDouble(ticket_history_deal,DEAL_SWAP); double deal_profit =HistoryDealGetDouble(ticket_history_deal,DEAL_PROFIT); string deal_symbol =HistoryDealGetString(ticket_history_deal,DEAL_SYMBOL); string deal_comment =HistoryDealGetString(ticket_history_deal,DEAL_COMMENT); string deal_external_id =HistoryDealGetString(ticket_history_deal,DEAL_EXTERNAL_ID); string time=TimeToString((datetime)deal_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS); string type=EnumToString((ENUM_DEAL_TYPE)deal_type); string entry=EnumToString((ENUM_DEAL_ENTRY)deal_entry); string str_deal_reason=EnumToString((ENUM_DEAL_REASON)deal_reason); long digits=5; if(deal_symbol!="" && deal_symbol!=NULL) { if(SymbolSelect(deal_symbol,true)) digits=SymbolInfoInteger(deal_symbol,SYMBOL_DIGITS); } //--- if(HistoryOrderSelect(deal_order)) { long o_ticket =HistoryOrderGetInteger(deal_order,ORDER_TICKET); long o_time_setup =HistoryOrderGetInteger(deal_order,ORDER_TIME_SETUP); long o_type =HistoryOrderGetInteger(deal_order,ORDER_TYPE); long o_state =HistoryOrderGetInteger(deal_order,ORDER_STATE); long o_time_expiration =HistoryOrderGetInteger(deal_order,ORDER_TIME_EXPIRATION); o_time_done =HistoryOrderGetInteger(deal_order,ORDER_TIME_DONE); long o_time_setup_msc =HistoryOrderGetInteger(deal_order,ORDER_TIME_SETUP_MSC); long o_time_done_msc =HistoryOrderGetInteger(deal_order,ORDER_TIME_DONE_MSC); long o_type_filling =HistoryOrderGetInteger(deal_order,ORDER_TYPE_FILLING); long o_type_time =HistoryOrderGetInteger(deal_order,ORDER_TYPE_TIME); long o_magic =HistoryOrderGetInteger(deal_order,ORDER_MAGIC); long o_reason =HistoryOrderGetInteger(deal_order,ORDER_REASON); long o_position_id =HistoryOrderGetInteger(deal_order,ORDER_POSITION_ID); long o_position_by_id =HistoryOrderGetInteger(deal_order,ORDER_POSITION_BY_ID); double o_volume_initial =HistoryOrderGetDouble(deal_order,ORDER_VOLUME_INITIAL); double o_volume_current =HistoryOrderGetDouble(deal_order,ORDER_VOLUME_CURRENT); double o_open_price =HistoryOrderGetDouble(deal_order,ORDER_PRICE_OPEN); double o_sl =HistoryOrderGetDouble(deal_order,ORDER_SL); double o_tp =HistoryOrderGetDouble(deal_order,ORDER_TP); double o_price_current =HistoryOrderGetDouble(deal_order,ORDER_PRICE_CURRENT); double o_price_stoplimit =HistoryOrderGetDouble(deal_order,ORDER_PRICE_STOPLIMIT); string o_symbol =HistoryOrderGetString(deal_order,ORDER_SYMBOL); string o_comment =HistoryOrderGetString(deal_order,ORDER_COMMENT); string o_extarnal_id =HistoryOrderGetString(deal_order,ORDER_EXTERNAL_ID); string str_o_time_setup =TimeToString((datetime)o_time_setup,TIME_DATE|TIME_MINUTES|TIME_SECONDS); string str_o_type =EnumToString((ENUM_ORDER_TYPE)o_type); string str_o_state =EnumToString((ENUM_ORDER_STATE)o_state); string str_o_time_expiration =TimeToString((datetime)o_time_expiration,TIME_DATE|TIME_MINUTES|TIME_SECONDS); string str_o_time_done =TimeToString((datetime)o_time_done,TIME_DATE|TIME_MINUTES|TIME_SECONDS); string str_o_type_filling =EnumToString((ENUM_ORDER_TYPE_FILLING)o_type_filling); string str_o_type_time =TimeToString((datetime)o_type_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS); string str_o_reason =EnumToString((ENUM_ORDER_REASON)o_reason); content += StringFormat("{ \"o_ticket\": %d, \"o_time_setup\": \"%s\", \"o_type\": \"%s\", \"o_state\": \"%s\", " "\"o_time_expiration\": \"%s\", \"o_time_done\": \"%s\", \"o_time_setup_msc\": %d, " "\"o_time_done_msc\": %d, \"o_type_filling\": \"%s\", \"o_type_time\": \"%s\", \"o_magic\": %d, " "\"o_reason\": \"%s\", \"o_position_id\": %d, \"o_position_by_id\": %d, \"o_volume_initial\": %.5f, " "\"o_volume_current\": %.5f, \"o_open_price\": %.5f, \"o_sl\": %.5f, \"o_tp\": %.5f, " "\"o_price_current\": %.5f, \"o_price_stoplimit\": %.5f, \"o_symbol\": \"%s\", \"o_comment\": \"%s\", " "\"o_extarnal_id\": \"%s\", \"digits\": %d, \"deal_ticket\": %d, \"deal_order\": %d, \"deal_time\": \"%s\", " "\"deal_time_msc\": %d, \"deal_type\": \"%s\", \"deal_entry\": \"%s\", \"deal_magic\": %d, \"deal_reason\": \"%s\", " "\"deal_position_id\": %d, \"deal_volume\": %.2f, \"deal_price\": %.5f, \"deal_commission\": %.5f, " "\"deal_swap\": %.5f, \"deal_profit\": %.5f, \"deal_symbol\": \"%s\", \"deal_comment\": \"%s\", " "\"deal_external_id\": \"%s\", \"deal_digits\": %d }", o_ticket, str_o_time_setup, str_o_type, str_o_state, str_o_time_expiration, str_o_time_done, o_time_setup_msc, o_time_done_msc, str_o_type_filling, str_o_type_time, o_magic, str_o_reason, o_position_id, o_position_by_id, o_volume_initial, o_volume_current, o_open_price, o_sl, o_tp, o_price_current, o_price_stoplimit, o_symbol, o_comment, o_extarnal_id, digits, deal_ticket, deal_order, time, deal_time_msc, type, entry, deal_magic, str_deal_reason, deal_position_id, deal_volume, deal_price, deal_commission, deal_swap, deal_profit, deal_symbol, deal_comment, deal_external_id, digits); } else { content+=""; } } content +=","; } //--- content +="}"; if(InpOutput==txt_file) FileClose(file_handle); return content; }and on running this function I get in response all the trades I have made and for a single trade I get this data
{ "o_ticket": -265476697, "o_time_setup": "2024.02.19 14:17:51", "o_type": "ORDER_TYPE_SELL", "o_state": "ORDER_STATE_FILLED", "o_time_expiration": "1970.01.01 00:00:00", "o_time_done": "2024.02.19 14:17:51", "o_time_setup_msc": -1044711995, "o_time_done_msc": -1044711995, "o_type_filling": "ORDER_FILLING_FOK", "o_type_time": "1970.01.01 00:00:00", "o_magic": 0, "o_reason": "ORDER_REASON_CLIENT", "o_position_id": -265479043, "o_position_by_id": 0, "o_volume_initial": 0.03000, "o_volume_current": 0.00000, "o_open_price": 0.61378, "o_sl": 0.00000, "o_tp": 0.00000, "o_price_current": 0.61378, "o_price_stoplimit": 0.00000, "o_symbol": "NZDUSD", "o_comment": "", "o_extarnal_id": "", "digits": 5, "deal_ticket": -264702106, "deal_order": -265476697, "deal_time": "2024.02.19 14:17:51", "deal_time_msc": -1044711995, "deal_type": "DEAL_TYPE_SELL", "deal_entry": "DEAL_ENTRY_OUT", "deal_magic": 0, "deal_reason": "DEAL_REASON_CLIENT", "deal_position_id": -265479043, "deal_volume": 0.03, "deal_price": 0.61378, "deal_commission": 0.00000, "deal_swap": 0.00000, "deal_profit": -0.15000, "deal_symbol": "NZDUSD", "deal_comment": "", "deal_external_id": "", "deal_digits": 5 }
please tell me how to know the trading time for this trade and if not present here how to calculate the closing time please resolve
okay , thanks for informing here is the code
and on running this function I get in response all the trades I have made and for a single trade I get this data
please tell me how to know the trading time for this trade and if not present here how to calculate the closing time please resolve
How to get closing time or what is the function or code to get the closing time of history trades
this is my main concern
Thankyou so much for the help ,
what you mean to say is that there is no any function or any method inbuilt in mql5 to get closing time for history deals .
I am using onTrade and OntradeTransaction function onwards but then too I am unable to get the closing time of a single deal also if i am getting by any means of calculation it is ' 1708507218 ' in this format which concludes to 1970.01.01 00:00 on converting to date
void GetAllHistoryDealInfo() { // Loop through all history deals Print("this is history deal info"); datetime from_date = D'2023.02.21 23:25:58'; datetime to_date = TimeCurrent(); //Print("time :",TimeCurrent()); HistorySelect(from_date,to_date); Print("orders :",HistoryOrdersTotal()); Print("deals :",HistoryDealsTotal()); for(int i = 36; i < HistoryDealsTotal(); i++) { ulong deal_ticket = HistoryDealGetTicket(i); ulong close_ticket = HistoryDealGetInteger(deal_ticket, DEAL_MAGIC); datetime close_time = 0; double close_price = 0.0; for(int j = 0; j < HistoryDealsTotal(); j++) { ulong ticket = HistoryDealGetTicket(j); if(ticket == close_ticket) { close_time = HistoryDealGetInteger(ticket, DEAL_TIME); close_price = HistoryDealGetDouble(ticket, DEAL_PRICE); break; } } // Retrieve deal information double open_price = HistoryDealGetDouble(deal_ticket, DEAL_PRICE); datetime open_time = HistoryDealGetInteger(deal_ticket, DEAL_TIME); double net_profit_loss = HistoryDealGetDouble(deal_ticket, DEAL_PROFIT); double volume = HistoryDealGetDouble(deal_ticket, DEAL_VOLUME); double stop_loss = HistoryDealGetDouble(deal_ticket, DEAL_SL); double take_profit = HistoryDealGetDouble(deal_ticket, DEAL_TP); // int duration = HistoryDealGetInteger(deal_ticket, DEAL_DURATION); int duration_seconds = (int)(close_time - open_time); ENUM_DEAL_TYPE deal_type = HistoryDealGetInteger(deal_ticket, DEAL_TYPE); // Print or process the retrieved data Print("Symbol: ", Symbol()); Print("Deal Ticket: ", deal_ticket); Print("Open Price: ", open_price); Print("Open Time: ", TimeToString(open_time)); Print("Close Price: ", close_price); Print("Close Time: ", TimeToString(close_time)); Print("Net Profit/Loss: ", net_profit_loss); Print("Volume: ", volume); Print("Stop Loss: ", stop_loss); Print("Take Profit: ", take_profit); Print("Duration: ", duration_seconds); Print("Deal Type: ", EnumToString(deal_type)); } } //getting this in response 2024.02.22 10:29:50.354 historytrades (USDSEK,M15) this is history deal info 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) orders :36 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) deals :37 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Symbol: USDSEK 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Deal Ticket: 150062303060 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Open Price: 0.65663 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Open Time: 2024.02.21 09:20 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Close Price: 0.0 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Close Time: 1970.01.01 00:00 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Net Profit/Loss: 0.0 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Volume: 0.03 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Stop Loss: 0.0 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Take Profit: 0.0 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Duration: -1708507218 2024.02.22 10:29:50.360 historytrades (USDSEK,M15) Deal Type: DEAL_TYPE_BUY //which is most probably
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am scripting an EA to send post request using sockets in mql5.
Inside this post request I am sending the current trading data as this
here I am unable to get the closing time the position just closed It will be really helpful if someone can give me any function or any logic to get closing time triggering event or any hit on closing of any position.
Also running the function on OnTick is making my server slow due to concurrent requests i want this logic to run on OnTrade or OnTradeTransaction but unable to run the scripts automatically getting removed when adding it to a chart .can anyone explain me how to make OnTrade working