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

 
davidb012:

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.

i don't know if i understand your nature of problem well.
here is my approach.

void OnTick()
{
   int CountSell = TodayClosed(OP_SELL,MagicSell);


}


int TodayClosed(int type, int magic)
{
   int history = 0;
   for(int order = 0; order <= OrdersHistoryTotal() - 1; order++)
   {
      bool select = OrderSelect(order,SELECT_BY_POS,MODE_HISTORY);
      if(TimeDay(OrderCloseTime())==Day() && OrderType()==type && OrderSymbol()==_Symbol && OrderMagicNumber()==magic) history++;
   }

   return history;
}
 
Mohamad Zulhairi Baba:

i don't know if i understand your nature of problem well.
here is my approach.

Thank you, appreciate the reply.

Yes, that might work. I'll give it go.

 
davidb012:

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.

That "number" is datetime start of today. E.G. 2018.03.14 00:00:00 (it cut hours, minutes and seconds)

If you do the same with OrderCloseTime() => OrderCloseTime()-OrderCloseTime()%86400 you get start of day that the order was closed.

And you can compare these two datetime. If the values are equal the order belong to today.

 
Petr Nosek:

That "number" is datetime start of today. E.G. 2018.03.14 00:00:00 (it cut hours, minutes and seconds)

If you do the same with OrderCloseTime() => OrderCloseTime()-OrderCloseTime()%86400 you get start of day that the order was closed.

And you can compare these two datetime. If the values are equal the order belong to today.

Thanks, that helps. I think I've got it working now.

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


 if (OrderCloseTime() => TodayTime)
 

Try this code to find out which trades are closed today

if(TimeToString(OrderCloseTime(), TIME_DATE) == TimeToString(TimeCurrent(), TIME_DATE))
{
   todayclosedtrades++;
}
Improperly formatted code edited by moderator.
 
davidb012 #: Looking again, I still can't work out what " date() " is.
See the line in blue, underlined. That is a link. You click on it to go to more information.