Step Wise Stop Loss, Help Please

 

Hi,

Newbe needs help. I am trying to move my sl to break even once i am 1/3 of the way to tp and again to 1/3 once I am 2/3 of the way to tp. I have two problems with my code. 1.) the modified sl is cycling between break even and 1/3 profit??? 2.) I am getting OrderModify error 1??? Please help. I can't find the break down in my logic.

void TrailingStop(int MagicNumber,double dblPoints)
  {
   double OneThird, TwoThird;
  
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
   {
   
      
  // Short Orders  
      
     if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
      {
        
        OneThird  = OrderOpenPrice()*2/3  +  OrderTakeProfit()*1/3;                                      // Calculate 1/3 Profit Price
        TwoThird  = OrderOpenPrice()*1/3  +  OrderTakeProfit()*2/3;                                      // Calculate 2/3 Profit Price        
           
     
Print("  Bid=",Bid,"  OP=",OrderOpenPrice(),"   TP=",OrderTakeProfit(),"  1x=",NormalizeDouble(OneThird,Digits),"  2x=",TwoThird,"  SL=",OrderStopLoss());
      
        if ( Bid < TwoThird)
         {
           if (OrderStopLoss() > NormalizeDouble(OneThird,Digits))
            { 
              OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OneThird,Digits), OrderTakeProfit(),0, SteelBlue);
Print("order modify Bid < 2x");
            }
         }
        else
         {
           if ( Bid < OneThird)
            {
              if (OrderStopLoss() > OrderOpenPrice())
               { 
                 OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(),0, SteelBlue);
Print("order modified Bid < 1x");
               }
            }
         }
      } 

          
  }    // end for()
  
  
}     // end TrailingStop()

 

A) I don't see OrderSelect() being used. Maybe it's taken for granted and excluded.

B) Add some error checking (+display) to OrderModify (and any other Order...). code. That 'OrderModify error 1' doesn't give much away

 
brewmanz:

A) I don't see OrderSelect() being used. Maybe it's taken for granted and excluded.

B) Add some error checking (+display) to OrderModify (and any other Order...). code. That 'OrderModify error 1' doesn't give much away


Thank you. That was it. I forgot the OrderSelect. Because it was modifing the order, I thought it was in the logic. But, I couldn't find and error. Again, thank you.