ATR Trailing not work in sell order
-
if(OrderType()==ORDER_TYPE_BUY
There is no such type in MT4.
-
double minstoplevel = MarketInfo(_Symbol,MODE_STOPLEVEL)*_Point;
You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
Requirements and Limitations in Making Trades - Appendixes - MQL4 TutorialOn some ECN type brokers, the value might be zero (the broker doesn't know). Use a minimum of two (2) PIPs.
The checks a trading robot must pass before publication in the Market - MQL5 Articles (2016)
after change to OP_BUY and OP_SELL
not work for sell
void TrailStops() { double ATR = iATR(NULL,0,14,0); double TrailingStop = ATR * 2 ; double buyStopLoss = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID)-TrailingStop,_Digits); double sellStopLoss = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK)+TrailingStop,_Digits); for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUY && buyStopLoss>OrderOpenPrice() && buyStopLoss>OrderStopLoss()) { if(!OrderModify(OrderTicket(),OrderOpenPrice(),buyStopLoss,OrderTakeProfit(),0,clrBlue)) { Print("Buy OrderModify error ",GetLastError(), " SL ",OrderStopLoss()," New SL ", buyStopLoss," Ticket Number : ",OrderTicket()); } } else if(OrderType()==OP_SELL && sellStopLoss<OrderOpenPrice() && sellStopLoss<OrderStopLoss()) { if(!OrderModify(OrderTicket(),OrderOpenPrice(),sellStopLoss,OrderTakeProfit(),0,clrWhite)) { Print("Sell OrderModify error ",GetLastError(), " SL ",OrderStopLoss()," New SL ", sellStopLoss," Ticket Number : ",OrderTicket()); } } } } }
in this coding ATR Trailing for buy order is work but sell order not apply
help me to solve error