How indicate ONLY in loss trades

 

Hi guys,

here i am again to ask you an help.

As in subject i wish EA close trades after X minute if position is in loss. So i write the following code:

void exitloss()
{  int ExpireX=60*MaxHour;

   for(int cnt=0; cnt<OrdersTotal(); cnt++)
      {
        if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES));
        {
         if(OrderOpenTime()<=TimeCurrent()-ExpireX)
         {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL)
            { 
               if(OrderProfit()<0)
               { Print("SUPERATO COUNTDOWN PER IL GAIN!!!!");
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),4,Red);
               }
            }
         }
      } 
    }
  }

Backtesting log return me on "SUPERATO TEMPO MAX.." and it closes every trade after my time.

 Seems OrderProfit<0 doesn't work...

How can i indicate only in loss positions?? 

Thank you for your help.

 
Il_Messia: Seems OrderProfit<0 doesn't work...
int ExpireX=60*MaxHour;
:
        if(OrderOpenTime()<=TimeCurrent()-ExpireX)
  1. Print out your variables, and find out why.
  2. if( seconds < seconds - nMinutes) will usually be true.
 
WHRoeder:
  1. Print out your variables, and find out why.
  2. if( seconds < seconds - nMinutes) will usually be true.
 Thankyou...seems order profit is always 0, still when i'm gain. I don't know what's wrong
 

Why do you think OrderProfit doesn't work?

Try to understand WHRoeder's post and fix your time calculation.

 

sorry maybe i can't understand something...i'm italian and it's easy don't understand.

time calculation was good but i can't comprend why Orderprofit return 0 value 

 

What does the semicolon at the end of the OrderSelect line do?

 
Solved using the orderprofit calculate 
Reason: