Check if order date is today?

To add comments, please log in or register
datatrading
13
datatrading  

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()) 
                   
                
)
Petr Nosek
1179
Petr Nosek  
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)
Alain Verleyen
36029
Alain Verleyen  
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.
Petr Nosek
1179
Petr Nosek  
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)
        {
         
        }
Alain Verleyen
36029
Alain Verleyen  
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

Petr Nosek
1179
Petr Nosek  
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)
        {
         
        }
Alain Verleyen
36029
Alain Verleyen  
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 ? ;-)
Petr Nosek
1179
Petr Nosek  
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 ;-)
To add comments, please log in or register