Check if order date is today?

 

How I can check if order day is today? I found quite ugly way . Should more elegant solution


for (int trade = OrdersHistoryTotal() - 1; trade >= 0; trade--) {
                if (OrderSelect(trade, SELECT_BY_POS, MODE_HISTORY) == true && OrderSymbol() == Symbol()
                   && TimeDay(OrderOpenTime())==TimeDay(TimeCurrent())
                   && TimeMonth(OrderOpenTime())==TimeMonth(TimeCurrent()) && TimeYear(OrderOpenTime())==TimeYear(TimeCurrent()) 
                   
                
)
 
datatrading:

How I can check if order day is today? I found quite ugly way . Should more elegant solution

I don't know if this way is less ugly but you can try it:

        if (OrderSelect(trade, SELECT_BY_POS, MODE_HISTORY) == true && OrderSymbol() == Symbol()
                   && OrderOpenTime()>=TimeCurrent()-TimeCurrent()%86400)
 
Petr Nosek:

I don't know if this way is less ugly but you can try it:

It would be less ugly by declaring a "today" variable outside the loop, instead of calculating it each time.
 
Alain Verleyen:
It would be less ugly by declaring a "today" variable outside the loop, instead of calculating it each time.

You are right as usual. But it was just an example and I used in that example only condition without the loop. But I can write the whole code for you.

BTW "OrderSelect(trade, SELECT_BY_POS, MODE_HISTORY) == true" is ugly too.

   datetime today=TimeCurrent()-TimeCurrent()%86400;
   for(int trade=OrdersHistoryTotal()-1;trade>-1;trade--)
      if(OrderSelect(trade,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==Symbol() && OrderOpenTime()>=today)
        {
         
        }
 
Petr Nosek:

You are right as usual. But it was just an example and I used in that example only condition without the loop. But I can write the whole code for you.

BTW "OrderSelect(trade, SELECT_BY_POS, MODE_HISTORY) == true" is ugly too.

datetime today=TimeCurrent()-TimeCurrent()%86400;

Using 2 times the same function in a row is ugly too

 
Alain Verleyen:

Using 2 times the same function in a row is ugly too

Because of you, I won't have lunch.  Hope you're satisfied.
   datetime today=TimeCurrent();
   today-=today%86400;
   for(int trade=OrdersHistoryTotal()-1;trade>-1;trade--)
      if(OrderSelect(trade,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==Symbol() && OrderOpenTime()>=today)
        {
         
        }
 
Petr Nosek:
Because of you, I won't have lunch.  Hope you're satisfied.
Well, as we are talking about ugliness, I am wondering why >=0 became >-1 ? ;-)
 
Alain Verleyen:
Well, as we are talking about ugliness, I am wondering why >=0 became >-1 ? ;-)
I don't want infringe copyright :D The result is the same and I refuse to update the code ;-)
 
Alain Verleyen:
Well, as we are talking about ugliness, I am wondering why >=0 became >-1 ? ;-)
Yes... That's bullying :P
Reason: