Hey guys.. I coded a trailing stop, but it doesn't work right, for Ex, if we have buy position, and first and second trailing stop triggers, if price goes down, second trailing stop modified its price and it goes back to the first one... this is the code, what is wrong with this code, how should i fix this problem. thanks.
Inserted Code
void TrailStops() { double Pointt = Point; if ((Point == 0.00001) || (Point == 0.001)) Pointt *= 10; int Mod; double sl=OrderStopLoss(); for(int cnt=OrdersTotal()-1;cnt>=0;cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(BreakEven>0) { if(Bid-OrderOpenPrice()>Pointt*BreakEven) { if(OrderStopLoss()<Bid-Pointt*BreakEven) { if(OrderType()==OP_BUY){ Mod = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-ModifiedStop*Pointt,Digits),OrderTakeProfit(),0,Blue); if(!Mod) Print("Error in OrderModify. Error code=",GetLastError()); else Print("Order modified successfully."); } if(OrderType()==OP_SELL){ Mod = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+ModifiedStop*Pointt,Digits),OrderTakeProfit(),0,Red); if(!Mod) Print("Error in OrderModify. Error code=",GetLastError()); else Print("Order modified successfully."); } } } if(Bid-OrderOpenPrice()>Pointt*2*BreakEven) { if(OrderStopLoss()<Bid-Pointt*2*BreakEven) { if(OrderType()==OP_BUY){ Mod = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-2*ModifiedStop*Pointt,Digits),OrderTakeProfit(),0,Blue); if(!Mod) Print("Error in OrderModify. Error code=",GetLastError()); else Print("Order modified successfully."); } if(OrderType()==OP_SELL){ Mod = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+2*ModifiedStop*Pointt,Digits),OrderTakeProfit(),0,Red); if(!Mod) Print("Error in OrderModify. Error code=",GetLastError()); else Print("Order modified successfully."); } } } } } }