stepped trail ordermodify errors

 

I'm getting order modify errors on this, not sure why - any ideas?


   //steppedtrail
   int FirstTP = 10;
   int SecondTP = 25;
   int ThirdTP = 50;
   int FourthTP = 100;
   int FifthTP = 200;
   int SixthTP = 300;
   if (usingsteppedTrail==true) {TradeTargetPrice=SixthTP;}

      if (usingsteppedTrail==true)
      {
         int totaltoStep = OrdersTotal();
         for(int itoStep=totaltoStep-1;itoStep>=0;itoStep--)
         {
            if( OrderSelect(itoBE,SELECT_BY_POS) && OrderCloseTime()==0 )
            {
               if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*FifthTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FourthTP,OrderTakeProfit(),0);}
               else if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*FourthTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*ThirdTP,OrderTakeProfit(),0);}
               else if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*ThirdTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*SecondTP,OrderTakeProfit(),0);}
               else if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*SecondTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FirstTP,OrderTakeProfit(),0);}
               else if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*FirstTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);}
               
               
               else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*FifthTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*FourthTP,OrderTakeProfit(),0);} 
               else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*FourthTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*ThirdTP,OrderTakeProfit(),0);} 
               else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*ThirdTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*SecondTP,OrderTakeProfit(),0);} 
               else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*SecondTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FirstTP,OrderTakeProfit(),0);} 
               else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*FirstTP))
               {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);} 
               
            }
      
          }
      }
 
SanMiguel:

I'm getting order modify errors on this, not sure why - any ideas?


Any ideas?

 

What is that itoBE variable?


if( OrderSelect(itoBE,SELECT_BY_POS) && OrderCloseTime()==0 )


I think it should be itoStep..

 
robofx.org:

What is that itoBE variable?



I think it should be itoStep..

Yes, of course - thanks.

Am I right in thinking the if else statements will only execute 1 of those statements and if 1 is true it skips all the rest?

I can't seem to find any trades in the strategy tester at more than

FirstTP
 

Suppose that (Bid-OrderOpenPrice()) >= Point*FifthTP) is true. Then all the other conditions will be true too: (Bid-OrderOpenPrice()) >= Point*FourfthTP) will be true, (Bid-OrderOpenPrice()) >= Point*ThirdTP) will be true and so on. So you finally end modifying the order with FirstTP.

 
robofx.org:

Suppose that (Bid-OrderOpenPrice()) >= Point*FifthTP) is true. Then all the other conditions will be true too: (Bid-OrderOpenPrice()) >= Point*FourfthTP) will be true, (Bid-OrderOpenPrice()) >= Point*ThirdTP) will be true and so on. So you finally end modifying the order with FirstTP.

but the else if should ignore that shouldn't it?


if do this else do that

if the first is true it doesn't go onto the else...

 
SanMiguel:

but the else if should ignore that shouldn't it?


if do this else do that

if the first is true it doesn't go onto the else...

Nope, the else if will not ignore the other checks. If it was if-else it would ignore the rest but not in your case with if-else if. In your case if the first if is true then all other if's are also true and will be executed.

So try to check the conditions in reverse order. First check FirstTP, SecondTP, ThirdTP and so on..

 
robofx.org:

Nope, the else if will not ignore the other checks. If it was if-else it would ignore the rest but not in your case with if-else if. In your case if the first if is true then all other if's are also true and will be executed.

So try to check the conditions in reverse order. First check FirstTP, SecondTP, ThirdTP and so on..

Hmm, that's strange :) I thought in most programming languages the ElseIf (as in VB) the else was part of the 1st if statement.

In which case why do we use the else statement at all? Why not just:

if this

if this

if this

if this


also if I swap them round then it will change the stop loss on every tick.


What about this:


               if (OrderType()==OP_BUY && OrderMagicNumber() == EA_ID)
               {
                  if((Bid-OrderOpenPrice()) >= Point*FifthTP)
                  {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FourthTP,OrderTakeProfit(),0);}
                  else {
                           if((Bid-OrderOpenPrice()) >= Point*FourthTP)
                           {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*ThirdTP,OrderTakeProfit(),0);}
                           else {
                                    if((Bid-OrderOpenPrice()) >= Point*ThirdTP)
                                    {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*SecondTP,OrderTakeProfit(),0);}
                                    else {
                                             if((Bid-OrderOpenPrice()) >= Point*SecondTP)
                                             {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FirstTP,OrderTakeProfit(),0);}
                                             else {
                                                      if((Bid-OrderOpenPrice()) >= Point*FirstTP)
                                                      {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);}
                                                  }
                                          }
                                  }
                         }
               }
 
SanMiguel:

Hmm, that's strange :) I thought in most programming languages the ElseIf (as in VB) the else was part of the 1st if statement.

In which case why do we use the else statement at all? Why not just:

if this

if this

if this

if this


also if I swap them round then it will change the stop loss on every tick.


What about this:


Yup, now it's different and looks good to me.

 
robofx.org:

Yup, now it's different and looks good to me.

Next problem :)

It seems to change the price back and forth between the values so that a stop is never actually hit until the zero stop.

Wouldn't the stop be hit first before the tick value changes the stop back to the next level below?


Maybe the >= part and the stop isn't hit until it moves past that point?

 
SanMiguel:

Next problem :)

It seems to change the price back and forth between the values so that a stop is never actually hit until the zero stop.

Wouldn't the stop be hit first before the tick value changes the stop back to the next level below?

I'm sorry but didn't get what the problem is. What is that zero stop ?

What exactly are you trying to accomplish?

Reason: