Counter orders per day - EA MQL4

 

Good mornig,

I'm writing an expert advisor that set a counter for the order opened on the current symbol. This is the code.

   int CountSymbolPositions=0;
   for(int trade=OrdersTotal()-1;trade>=0;trade--)
       {
         if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
         continue;
         if(OrderSymbol()==Symbol())
         {
         if((OrderType()==OP_SELL||OrderType()==OP_BUY) && 
         (OrderMagicNumber()==1))
         CountSymbolPositions++;
         }
       }

Now I need to set another counter for the order closed  on the current day for the current symbol.

This counter need to reset every day, but I don't know how to write it. Can someone please help me?

 
  1. Why did you post your MT4 question in the Root / 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. Trader1529: but I don't know how to write it
    Your code counts current open orders. You should make that a function and return the count.
  3. If you open all orders and then later start closing, you can just remember the largest count in a static/global variable. Number closed=largest - current. Reset the count at the start of a new day. Same as new bar test, but using date:
    static datetime currentDay=0;
    datetime previousDay = currentDay; currentDay = date();
    bool isNewDay = currentDay != previousDay;
              Find bar of the same time one day ago - Simple Trading Strategies - MQL4 programming forum

  4. Otherwise, you will have to go through history and count all orders closed on today's date.
    1. Do not assume history has only closed orders.
                OrderType() == 6, 7 in the history pool? - MQL4 programming forum

    2. Do not assume history is ordered by date, it's not.
                Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum

    3. Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
                "balance" orders in account history - Day Trading Techniques - MQL4 programming forum
      Broker History
      FXCM
      Commission - <TICKET>
      Rollover - <TICKET>

      >R/O - 1,000 EUR/USD @0.52

      #<ticket>  N/A
      OANDA
      Balance update
      Financing
 
In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.
Reason: