for(int i=0; i<=OrdersTotal(); i++) { if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { continue; } if(OrdersTotal() == 0) { continue; } OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
- OrderSelect when i == OrdersTotal will ALWAYS fail. positions are [0 .. total-1]
- When closing you must count down.
- What is the point of selecting the order twice?
- If you fix your loop, it does nothing when OrdersTotal == 0, so no need to check.
for(int i=OrdersTotal()-1; i>=0; i--) if( OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
- Drop your isStopLoss, lastStopLoss they are unnecessary.
- Check your return codes What are Function return values ? How do I use them ? - MQL4 forum
- Filter by pair/magic number so it is compatible with other EAs including itself on other charts and manual trading.
- initialStopLoss*Point means the EA doesn't adjust for 4/5 digit brokers.
Very big thank you for your kind reply. Will try to modify the EA and post a newer version here.
Wish you the very best for the upcoming year.
Ok, I cleaned up my code a bit.
But I even don't know how to fix the problem, that the EA trails every order with a stoploss. The problem is that I have the variables "lastStopLoss" e.g.
My idea is that I write them into an array and check every order with this method. What can I do better so the program works how I want it?
Best regards

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello community,
I programmed an Expert Advisor that sets the SL to 2 Points for only ONE order at a time. When the order goes into profit it takes the SL to +2 Points and trails every +1 Point to 2.8 Points, 3.6 Points and so on.
That's the logic behind this program. But it only works for one order at a time. How can I modify this EA that it sets SL and trails it for every open order of the current chart symbol?
Below you see my code. Feel free to ask questions. Thank you very much!