Closed orders check

 

Hello, everyone..

What is the best way to check if there have been any orders closed from midnight to the current time on the same day?

The next day the check should start from 0 again.I am thinking of using a OrdersHistoryTotal (0)..

Thank you for any recommendations.

R

 
resin17:

Hello, everyone..

What is the best way to check if there have been any orders closed from midnight to the current time on the same day?

The next day the check should start from 0 again.I am thinking of using a OrdersHistoryTotal (0)..

It is not clear what you mean by "a OrdersHistoryTotal (0)"

It is also not clear what "the best way" is to do anything. A way would be to to search the entire order history, possibly neglecting trades with the wrong magic number, and/or and the wrong symbol. Then reject any which closed earlier than today. Count any that are left. So this is an OrderSelect using MODE_HISTORY. The time of the start of the day should be iTime with a period of D1 and a shift of 0.

 

Sorry, a zero in the brackets is a typo

I am using OrdersTotal and OrderSelect to find and count any currently open orders with a particular Magic number and this works fine. I also need to identify if there have been orders closed with the same Magic number today (don't have to count them, though)..My EA uses ticks, hence I am not sure if iTime can be used...

 
resin17:
What is the best way to check if there have been any orders closed from midnight to the current time on the same day?

The next day the check should start from 0 again.I am thinking of using a OrdersHistoryTotal (0)..
datetime now = Time[0],
         bod = now - now % 86400;
    for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)  // Only orders w/
    &&  OrderMagicNumber()  == Magic.Number             // my magic number
    &&  OrderSymbol()       == chart.symbol             // and my pair.
    &&  OrderType()         <= OP_SELL//Avoid cr/bal https://www.mql5.com/en/forum/126192
    &&  OrderCloseTime()    >= bod
    ){
see also Order History sort by closing date - MQL4 forum
 

resin17:

My EA uses ticks, hence I am not sure if iTime can be used...

Well if you are running an EA on MT4 then the time is still there. I assume that when you say "my EA uses ticks" you simply mean that you respond and test for entry and/or exit on every tick. That has nothing to do with when a trade was closed. That time information is automatically stored by MT4 so you can certainly work by time and use iTime or WHR's code above.
 
yes, that's right, i meant that the EA runs it's logic on every tick. I will check both suggestions. Thanks!
Reason: