Finding total number of orders closed today....for an EA. Datetime difficulties

 

I have code within my EAs that shows on the chart, the total open and closed orders for that EA and magic number.

I have been trying to modify it to only show closed orders for the current day.

I have read and re-read the section describing the datetime function for MT4, but cannot work out how to incorporate one more line into my code to find only the orders closed today for this EA.

      if ((OrderType()        == OP_SELL)       &&              
          (OrderSymbol()      == Symbol())      &&                             
          (OrderMagicNumber() == MagicNumber)   &&
          
          (OrderCloseTime()   == TimeCurrent()    ))                  // this is the bit I cannot work out

            {
             SellOrders ++;                                          
            }  


I know I probably need to convert the OrderCloseTime() for the found orders, and compare to the CurrentTime(), also converted to string/double or what not, but I can't figure it out.

Anybody help please?

 
davidb012:

I have code within my EAs that shows on the chart, the total open and closed orders for that EA and magic number.

I have been trying to modify it to only show closed orders for the current day.

I have read and re-read the section describing the datetime function for MT4, but cannot work out how to incorporate one more line into my code to find only the orders closed today for this EA.


I know I probably need to convert the OrderCloseTime() for the found orders, and compare to the CurrentTime(), also converted to string/double or what not, but I can't figure it out.

Anybody help please?

Sort in OrderHistoryTotal() pool.
 
Mohamad Zulhairi Baba:
Sort in OrderHistoryTotal() pool.

Thanks, but I don't see what sorting them will do.

I'm already searching for the trades within the OrderHistory pool..........and finding all the closed trades isn't the issue. The challenge, is only selecting those that were closed today.

 
davidb012:

Thanks, but I don't see what sorting them will do.

I'm already searching for the trades within the OrderHistory pool..........and finding all the closed trades isn't the issue. The challenge, is only selecting those that were closed today.

Yes they do. Find all closed trade, will filtering according to your requirements. I.e closed today.
 
Mohamad Zulhairi Baba:
Yes they do. Find all closed trade, will filtering according to your requirements.

Thanks again, but you're really not understanding the issue. Thanks anyway.

How do I filter from all the closed orders, only those that were closed today?

Clearly I have to use something like

if (OrderCloseTime()   == TimeCurrent() 

But that doesn't work. How do I modify that, so it does work?

There will be hundreds of closed trades with this magic number, and for this symbol........I only want to find those closed today.

 

Thanks, I had already looked at this entry of yours, but couldn't make sense of it.

Looking again, I still can't work out what " date() " is.

Looks like you're saying, date = TimeCurrent().

datetime    date(datetime when=0)

//and

datetime    when = TimeCurrent();

So your expression above

if( OrderCloseTime() >= date() )

is pretty much the same as my

if (OrderCloseTime()   == TimeCurrent() 		

..which doesn't work.

 

Clearly what I'm after, is some way of converting TimeCurrent() to a number that represents today's date......and just the day, not the time of day.

and then, in a similar way, convert OrderCloseTime() to a number that represents that date........and just the day, not the time of day.

then if they match, the order was closed today.


However, I can't work out how to get a number out of TimeCurrent() or OrderCloseTime() that just represents today's date.

 
davidb012:
 

However, I can't work out how to get a number out of TimeCurrent() or OrderCloseTime() that just represents today's date.

TimeCurrent()-TimeCurrent()%86400
 
Petr Nosek:

Can you explain what that number is. It's coming out as 1520467200 at the moment. 

and

how could that be compared to OrderCloseTime()? 

Thanks, appreciate any help.

 

Okay, think I've got it,

       
int TodayTime = TimeCurrent()   - TimeCurrent()%86400;
int CloseTime = OrderCloseTime()- OrderCloseTime()%86400;

if (CloseTime  >= TodayTime)

Not quite sure what the math is doing, but looks the result I'm getting is correct.

Thanks

Reason: