int Free_Trade = 250; for (int i = 1; i <= OrdersTotal(); i++) { //Don't count up !!!! if (!OrderSelect(i, SELECT_BY_POS)) continue; if (OrderType() == OP_BUY) if (Bid > (OrderOpenPrice() + (Free_Trade*Point))) { if (OrderStopLoss() < OrderOpenPrice()) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+Point, OrderTakeProfit(), 0, Blue) // this correction } } } } }
this way it will ending error 1
But also Don't count up checking trades
Read Loops and Closing or Deleting Orders
The moment trades get closed why the EA is doing the loop it can fail
Thanks for the tip about counting down, rather than up - I've modified my code accordingly.
The correction you suggested also worked - can you please explain to me why setting SL to OrderOpenPrice() causes errors but setting it to OrderOpenPrice()+Point doesn't?
Thanks for the tip about counting down, rather than up - I've modified my code accordingly.
The correction you suggested also worked - can you please explain to me why setting SL to OrderOpenPrice() causes errors but setting it to OrderOpenPrice()+Point doesn't?
https://www.mql5.com/en/forum/136997 Can price != price ?
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
I'm coding an EA and I'd like to move the stoploss of an order up to the opening price if the Bid is a certain number of points above the price the order was opened at.
I have some code, and it does modify the stoploss correctly, however it also generates an OrderModify Error 1 on each tick too - so from what I can gather it's trying to modify the stoploss on each tick, not just when my conditions are met.
Below is the code I'm using, any help would be greatly appreciated!