Traling stop help

 

Hello, I am coding ea and I dont know what is wrong :?

so I try to code traling stop but it works bad with sell, so my code is:

this work good:

if (OrderType() == OP_BUY)

{

if(Ask-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Ask-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*TrailingStop,OrderTakeProfit(),0,Blue);

return(0);

}

}

}

here is something wrong, but cant understand what:

if (OrderType() == OP_SELL)

{

if(OrderOpenPrice()-Ask>Point*TrailingStop)

{

if(OrderStopLoss()>Ask+Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Blue);

return(0);

}

}

}

Someone can tell me what is wrong with SELL code ? :?

 
rokasearner:
Hello, I am coding ea and I dont know what is wrong :?

so I try to code traling stop but it works bad with sell, so my code is:

this work good:

here is something wrong, but cant understand what:

Someone can tell me what is wrong with SELL code ? :?

Try changing this :

if(OrderStopLoss()>Ask+Point*TrailingStop)

to this :

if(OrderStopLoss()==0 || OrderStopLoss()>Ask+Point*TrailingStop)

 

I dont know what is the reason, but it worked, thanks

 
rokasearner:
I dont know what is the reason, but it worked, thanks

Your initial stop loss is 0. That is why in the case of a sell order you needed additional check : because OrderStopLoss()>Ask+Point*TrailingStop will not be fulfilled when order stop loss == 0

Reason: