Download MetaTrader 5
To add comments, please log in or register
Search in documentation is available via MetaTrader 5. Search and learn!
Il_Messia
44
Il_Messia 2016.08.21 14:51 

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.

whroeder1
13605
whroeder1 2016.08.21 19:02  
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.
Il_Messia
44
Il_Messia 2016.08.21 20:53  
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
peter.MT4Web
158
peter.MT4Web 2016.08.21 21:43  

Why do you think OrderProfit doesn't work?

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

Il_Messia
44
Il_Messia 2016.08.21 22:06  

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 

peter.MT4Web
158
peter.MT4Web 2016.08.21 23:10  

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

Il_Messia
44
Il_Messia 2016.08.22 12:53  
Solved using the orderprofit calculate 
/
To add comments, please log in or register