Just a little fixing:
void trail_order(int type) { if(UseTrailingStopLoss) { if(type==OP_BUY) { //if((Bid-OrderOpenPrice())>(Point*TrailingStopLoss)) //{ if(OrderStopLoss()<(Bid-Point*TrailingStopLoss)) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStopLoss,OrderTakeProfit(),0,Green); } //} } if(type==OP_SELL) { //if((OrderOpenPrice()-Ask)>(Point*TrailingStopLoss)) // { if((OrderStopLoss()>(Ask+Point*TrailingStopLoss)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStopLoss,OrderTakeProfit(),0,Red); } // } } } }
Hello. I am working on my EA and I am having some problems with trailing stop loss. Here is code I have found on some tutorial that I use for trailing:
Problem I am having is that trailing does not start immediately after market go in my favor, but after greater distance is made. For example, if BUY order is sent at price 1.200, and I use stop loss of 15 pips, then it is set to 1.185. If price raise to 1.201, trailing stop loss should change stop loss to 1.186, but it does not. Does anybody know what to change in code above to make this work?
Another problem I have is that sometimes trailing stop loss goes mad. Here is report from journal:
Thanks in advance for all help.