How can I access the history of daily orders instead of OrdersHistoryTotal()?

 

I want to count the number of losses per day instead of lifetime losses. How can that be done? -> MQL4

PS: I tried to post it in MQL4 forum, but as I click on forum at www.mql4.com it redirects me here.

 
SamSuleymanov: I want to count the number of losses per day instead of lifetime losses. How can that be done? -> MQL4

PS: I tried to post it in MQL4 forum, but as I click on forum at www.mql4.com it redirects me here.

The MQL4.com Forum was merged into MQL5.com many years ago.

Post in the MQL4 section (last one on the list) of the MQL5 Forum -> https://www.mql5.com/en/forum/mql4.

 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Use OrdersHistoryTotal and loop through all the orders. Filter by today's date.
              Find bar of the same time one day ago - MQL4 programming forum 2017.10.06

 
SamSuleymanov:

I want to count the number of losses per day instead of lifetime losses. How can that be done? -> MQL4

PS: I tried to post it in MQL4 forum, but as I click on forum at www.mql4.com it redirects me here.


It can be done simply.

//+------------------------------------------------------------------+
//|                                                  DayLosCount.mq4 |
//|                                 Copyright 2019, Haskaya Software |
//|                                   https://www.haskayayazilim.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Haskaya Software"
#property link      "https://www.haskayayazilim.net"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int DayNow=TimeDay(TimeLocal());
    int i,hstTotal=OrdersHistoryTotal(); 
    int DayCount=0;
    double DayLost=0;
  for(i=0;i<hstTotal;i++) 
    { 
     //---- check selection result 
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) 
       { 
        Print("Access to history failed with error (",GetLastError(),")"); 
        break; 
       } 
       if(TimeDay(OrderCloseTime())==DayNow && (OrderProfit()+OrderSwap()+OrderCommission())<0)
       {
        DayCount=DayCount+1;
        DayLost=DayLost+OrderProfit()+OrderSwap()+OrderCommission();
       }
     // some work with order 
    }
    Comment(" Day Now:"+string(DayNow)," Day Lost Count:"+string(DayCount)," Day Lost Money:"+DoubleToStr(DayLost,2));
  }
//+------------------------------------------------------------------+
 
Mehmet Bastem: It can be done simply.
  int DayNow=TimeDay(TimeLocal());

All times of trades are broker's time. Your time zone is irreverent.

 
Mehmet Bastem #:


It can be done simply.

Brilliant!
Thank you very much bro!

 
William Roeder #:

All times of trades are broker's time. Your time zone is irreverent.

Yes .. agree.
Should be replaced with  TimeCurrent().