Please insert the code correctly: when editing a message, press the button
and paste your code into the pop-up window

Syarif Nur Arief #:
Ok, was type above from my mobile phone browser, there's no code insert button,
Ok, was type above from my mobile phone browser, there's no code insert button,
Will edit on my desktop PC.
Thank u
Example: Daily Trading Statistics:
So below code to count closed profit current day is ok on mql5 :
MqlDateTime SDateTime; TimeToStruct(TimeCurrent(),SDateTime); SDateTime.hour=0; SDateTime.min=0; SDateTime.sec=0; datetime from_date=StructToTime(SDateTime); // From date SDateTime.hour=23; SDateTime.min=59; SDateTime.sec=59; datetime to_date=StructToTime(SDateTime); // To date to_date+=60*60*24; HistorySelect(from_date,to_date); int trades_of_day=0; double wining_trade=0.0; double losing_trade=0.0; double total_profit=0.0; uint total=HistoryDealsTotal(); ulong ticket=0; //--- for all deals for(uint i=0; i<total; i++) { //--- try to get deals ticket if((ticket=HistoryDealGetTicket(i))>0) { long entry=HistoryDealGetInteger(ticket,DEAL_ENTRY); if(entry==DEAL_ENTRY_IN) continue; //--- get deals properties trades_of_day++; double deal_commission=HistoryDealGetDouble(ticket,DEAL_COMMISSION); double deal_swap=HistoryDealGetDouble(ticket,DEAL_SWAP); double deal_profit=HistoryDealGetDouble(ticket,DEAL_PROFIT); double profit=deal_commission+deal_swap+deal_profit; if(profit>0.0) wining_trade+=profit; if(profit<0.0) losing_trade+=profit; total_profit+=profit; } }
Complete Function of Closed_Profit_Today(), Like this :
double Closed_Profit_Today() { MqlDateTime SDateTime; TimeToStruct(TimeCurrent(),SDateTime); datetime SDateTime.hour=0; datetime SDateTime.min=0; datetime SDateTime.sec=0; datetime from_date=StructToTime(SDateTime); // From date datetime SDateTime.hour=23; datetime SDateTime.min=59; datetime SDateTime.sec=59; datetime to_date=StructToTime(SDateTime); // To date to_date+=60*60*24; HistorySelect(from_date,to_date); int trades_of_day=0; double wining_trade=0.0; double losing_trade=0.0; double total_profit=0.0; uint total=HistoryDealsTotal(); ulong ticket=0; //--- for all deals for(uint i=0; i<total; i++) { //--- try to get deals ticket if((ticket=HistoryDealGetTicket(i))>0) { ///////////---- //--- get deals properties trades_of_day++; double deal_commission=HistoryDealGetDouble(ticket,DEAL_COMMISSION); double deal_swap=HistoryDealGetDouble(ticket,DEAL_SWAP); double deal_profit=HistoryDealGetDouble(ticket,DEAL_PROFIT); double profit=deal_commission+deal_swap+deal_profit; if(profit>0.0) wining_trade+=profit; if(profit<0.0) losing_trade+=profit; total_profit+=profit; } } return(total_profit); }
Hello, once we have set the function Closed_Profit_Today, do we have to create a loop "for" ? because when I get total_profit I have 0.
thank you
thank you

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
in Mql4, this code is work nice to calculate total closed profit today (current day),