English

## Trailing step

 120 DeanDeV 2015.06.25 19:38   Hey guys,I am trying to make a trailing step. Essentially like a trailing stop, but instead of moving the stop loss every point in profit, it only moves the stop loss after X amount in profit. Below is my code (tries to modify as soon as order enters and I get a constant OrderModify error 1):```for(int z=OrdersTotal()-1; z>=0; z--)   {    if(!OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) continue;     if(OrderMagicNumber()==MagicNumber)      if(OrderSymbol()==Symbol())       if(OrderType()==OP_BUY)        {         for(int tstepb=0; tstepb>=0; tstepb++)          {           if(Bid-OrderOpenPrice()>=(WhenToTrail*Point)+(TrailingStep*tstepb*Point))            if(OrderStopLoss()=0; tsteps++)          {           if(OrderOpenPrice()-Ask>=(WhenToTrail*Point)+(TrailingStep*tsteps*Point))            if(OrderStopLoss()>Ask+(TrailingStep*Point) || OrderStopLoss()==0)             {              bool sellstep=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(TrailingStep*Point),OrderTakeProfit(),0,clrRed);             }          }        }   }``` Am I going about this incorrectly..? Is my logic incorrect..?Any help is appreciated!
 Moderator3406 GumRai 2015.06.26 06:52 #   ```        for(int tstepb=0; tstepb>=0; tstepb++) //Why use a loop, especially a never-ending loop          {           if(Bid-OrderOpenPrice()>=(WhenToTrail*Point)+(TrailingStep*tstepb*Point))            if(OrderStopLoss()=WhenToTrail*Point)      {       if(OrderOpenPrice()-OrderStopLoss()>Point)          new_stop_loss=OrderOpenPrice();       else          new_stop_loss=Bid-WhenToTrail*Point;       if(new_stop_loss-OrderStopLoss()>=(TrailingStep*Point))         {          bool buytstep=OrderModify(OrderTicket(),OrderOpenPrice(),new_stop_loss,OrderTakeProfit(),0,clrBlue);         }      }``` That is for your buy orders, not compiled or tested.Don't forget that for sell orders you will need to take into account orders that may not have an initial SL.