How indicate ONLY in loss trades

Back to topics list To post a new topic, please log in or register
avatar
15
Il_Messia 2016.08.21 16: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.

 

avatar
12992
WHRoeder 2016.08.21 21: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.
avatar
15
Il_Messia 2016.08.21 22: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
avatar
108
eddie 2016.08.21 23:43 #
 

Why do you think OrderProfit doesn't work?

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



avatar
15
Il_Messia 2016.08.22 00: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 

avatar
108
eddie 2016.08.22 01:10 #
 

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


avatar
15
Il_Messia 2016.08.22 14:53 #
 
Solved using the orderprofit calculate 
Back to topics list  

To add comments, please log in or register