Hi! Why am i getting modify order error 1 here?
Hi! Why am i getting modify order error 1 here?
if (OrderType() == OP_BUY && OrderStopLoss()!=Bid - TrailingStop)
Hi! Why am i getting modify order error 1 here?
void TrailStops(){ double ATR = iATR(NULL,0,14,0); double TrailingStop = ATR * 2 ; for (int i = OrdersTotal() - 1; i >=0; i--) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if ( OrderSymbol()==Symbol() ) { if (OrderType() == OP_BUY && OrderStopLoss()!=Bid - TrailingStop ) { if (Bid - OrderOpenPrice() > TrailingStop && OrderStopLoss() < Bid - TrailingStop ) { if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop, OrderTakeProfit(), 0, Green)) { Print("BUY OrderModify error ",GetLastError()," SL ",OrderStopLoss()," New SL ",Bid - TrailingStop ," Ticket Number:",OrderTicket()); } return; } } else if (OrderType() == OP_SELL && OrderStopLoss()!=Bid - TrailingStop ) { if (OrderOpenPrice() - Ask > TrailingStop && OrderStopLoss() > Ask + TrailingStop) { if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop, OrderTakeProfit(), 0, Green)) { // Print("OrderModify error ", GetLastError()); Print("SELL OrderModify error ",GetLastError()," SL ",OrderStopLoss()," New SL ",Bid - TrailingStop," Ticket Number:",OrderTicket()); } return; } } } } }
Could you please run this and upload the screenshot?
ok. Please using Normalizedouble
Order Stop Lost is =1.0465 New Sl=1.04656565654. When both are the same, you get error 1. For this you need to use the NormalizeDouble command.
The corrected code has been added.
void TrailStops(){ double ATR = iATR(NULL,0,14,0); double TrailingStop = ATR * 2 ; for (int i = OrdersTotal() - 1; i >=0; i--) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if ( OrderSymbol()==Symbol() ) { if (OrderType() == OP_BUY && OrderStopLoss()!=NormalizeDouble((Bid - TrailingStop),Digits) ) { if (Bid - OrderOpenPrice() > TrailingStop && OrderStopLoss() < Bid - TrailingStop ) { if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble((Bid - TrailingStop),Digits), OrderTakeProfit(), 0, Green)) { Print("BUY OrderModify error ",GetLastError()," SL ",OrderStopLoss()," New SL ",Bid - TrailingStop ," Ticket Number:",OrderTicket()); } return; } } else if (OrderType() == OP_SELL && OrderStopLoss()!=NormalizeDouble((Bid - TrailingStop),Digits) ) { if (OrderOpenPrice() - Ask > TrailingStop && OrderStopLoss() > Ask + TrailingStop) { if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble((Ask + TrailingStop),Digits), OrderTakeProfit(), 0, Green)) { // Print("OrderModify error ", GetLastError()); Print("SELL OrderModify error ",GetLastError()," SL ",OrderStopLoss()," New SL ",Bid - TrailingStop," Ticket Number:",OrderTicket()); } return; } } } } }
ok. Please using Normalizedouble
Order Stop Lost is =1.0465 New Sl=1.04656565654. When both are the same, you get error 1. For this you need to use the NormalizeDouble command.
The corrected code has been added.
Thank you so much that did the job! I fugured out that i need to normalize it... but i didn't know where to place it...
I have one more thing if you could help me.... This trailing stop when conditions are true, changes on every tick , which i dont like, because it basically sets stop at price High.
I would like that it sets only on price Close. Is that possible?
Thank you so much that did the job! I fugured out that i need to normalize it... but i didn't know where to place it...
I have one more thing if you could help me.... This trailing stop when conditions are true, changes on every tick , which i dont like, because it basically sets stop at price High.
I would like that it sets only on price Close. Is that possible?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use