Job finished
Specification
I need a simple MT5 Expert Advisor (MQL5) programmed exactly according to the following rules.
The EA is a continuous candle-direction reversal strategy.
Candle signal:
- Close > Open = BUY signal
- Close < Open = SELL signal
- Close = Open = no change
Trading logic:
- After each candle has fully closed, use that completed candle to determine the required trade direction.
- The signal is acted upon at the opening of the following candle.
- If the signal is BUY and a BUY is already open, do nothing and continue holding BUY.
- If the signal is SELL and a SELL is already open, do nothing and continue holding SELL.
- If the signal changes from BUY to SELL, close the BUY and immediately open a SELL.
- If the signal changes from SELL to BUY, close the SELL and immediately open a BUY.
- A Doji (Close = Open) does not close or change the existing position.
Position rules:
- Only ONE position can be open at any time.
- Never have BUY and SELL positions open simultaneously.
- Consecutive candles in the same direction must NOT create additional positions.
- There is NO Stop Loss.
- There is NO Take Profit.
- The only exit is a reversal into the opposite direction.
Example:
Bullish → BUY
Bullish → continue BUY
Bullish → continue BUY
Bearish → close BUY + open SELL
Bearish → continue SELL
Doji → continue SELL
Bullish → close SELL + open BUY
EA startup:
When the EA is first activated, use the most recently completed non-Doji candle to determine the initial direction and open the corresponding position.
Timeframe:
The EA must work on all MT5 timeframes and use the timeframe of the chart to which it is attached.
Position size:
Lot size should be a user-adjustable input, with 1.00 lot as the default.
Please confirm that you understand the above logic before development begins.
I also require the complete MQL5 source code (.mq5), as well as the compiled EA (.ex5).