Hello everyone,
I am working on an EA that follows an Alternating Buy/Sell strategy based on price movements, but I have encountered an issue where it keeps opening consecutive Sell orders instead of alternating between Buy and Sell.
Strategy Requirements:
- The EA starts with a manual Buy order (0.1 lot).
- Take Profit (TP) = $4, Stop Loss (SL) = $6 (Same for all trades).
- If the price drops $2 from the initial buy price, the EA should place a Sell order (0.25 lot).
- If the price returns to the initial price (+$2 from the sell entry), the EA should place another Buy order (0.35 lot).
- The process should continue in an alternating sequence: Buy → Sell → Buy → Sell, using increasing lot sizes from predefined arrays.
- If any order hits TP or SL, the EA should close all positions and reset.
- If the price doesn’t reach TP but returns to the initial price, the EA should place the next order with the next lot size.
Current Issues:
✅ The EA opens orders correctly, places TP and SL correctly, and opens a Sell order when the price drops $2 as expected.
❌ The problem is that after opening a Sell order, the EA keeps opening consecutive Sell orders instead of alternating back to Buy.
❌ It does not detect when the price has returned to the initial level to place the next Buy order.
I have tried debugging the isBuyActive flag and adjusting conditions in CheckForNewOrders() , but I can’t seem to fix the issue.
CODE IS ATTACHED
I would really appreciate any insights or fixes to ensure the EA correctly follows the Buy → Sell → Buy → Sell pattern.
Thanks in advance!
Traders and coders are working for free:
- if it is interesting for them personally, or
- if it is interesting for many members on this forum.
Freelance section of the forum should be used in most of the cases.

- 2025.03.13
- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone,
I am working on an EA that follows an Alternating Buy/Sell strategy based on price movements, but I have encountered an issue where it keeps opening consecutive Sell orders instead of alternating between Buy and Sell.
Strategy Requirements:
Current Issues:
✅ The EA opens orders correctly, places TP and SL correctly, and opens a Sell order when the price drops $2 as expected.
❌ The problem is that after opening a Sell order, the EA keeps opening consecutive Sell orders instead of alternating back to Buy.
❌ It does not detect when the price has returned to the initial level to place the next Buy order.
I have tried debugging the isBuyActive flag and adjusting conditions in CheckForNewOrders() , but I can’t seem to fix the issue.
CODE IS ATTACHED
I would really appreciate any insights or fixes to ensure the EA correctly follows the Buy → Sell → Buy → Sell pattern.
Thanks in advance!