Specification
MT5 5-EMA + ATR Fixed-Money-Risk EA
I need an MT5 Expert Advisor running on the 5-minute chart using EMA(5) and ATR(14).
SHORT SETUP
- Use only completed 5-minute candles.
- A SHORT alert candle forms when the entire candle is above EMA(5), meaning even the LOW/wick does not touch the EMA.
- Mark that candle’s LOW as the SHORT trigger price.
- If another completed candle also stays completely above EMA(5), replace the old trigger with the LOW of the latest qualifying candle.
- When market price breaks below the latest trigger LOW, immediately open one SELL trade.
- If price touches/crosses EMA(5) before entry happens, cancel that setup and wait for a fresh qualifying alert candle.
LONG SETUP
- Exact opposite logic: a LONG alert candle forms when the entire candle is below EMA(5), meaning even its HIGH/wick does not touch EMA(5).
- Mark the latest qualifying candle’s HIGH as the trigger. When price breaks above it, open one BUY trade.
ATR STOP LOSS
- At the exact moment the trade is opened, read the current 5-minute ATR(14) and freeze this ATR value for that trade.
- For a SHORT trade, the stop-loss distance must equal that frozen ATR(14) and the SL is placed above the entry.
- For a LONG trade, the stop-loss distance must equal that frozen ATR(14) and the SL is placed below the entry.
- The frozen ATR must NOT change after the trade has opened.
FIXED MONEY LOSS / AUTOMATIC LOT SIZE
- Add an input called Risk Amount, entered in my account currency, e.g. AED 25 / AED 50 / AED 100.
- The EA must automatically calculate the lot size so that if the ATR stop-loss is hit, the planned loss is as close as possible to my Risk Amount without exceeding it.
- Example: if my Risk Amount is AED 50 and available broker lot sizes would produce either approximately AED 40 loss or AED 70 loss, always choose the lower AED 40 risk.
- Always round the calculated lot size DOWN to the nearest permitted broker lot/volume step. Never round upward beyond my selected Risk Amount.
- If the broker’s minimum lot would already risk more than my Risk Amount, do not take the trade.
- If available margin is insufficient, do not take the trade.
- Lot calculation must use the actual symbol contract/tick value and actual entry-to-SL distance so it works correctly on BTC, Gold, Nasdaq, Oil, etc.
TAKE PROFIT
- Add an input called TP ATR Multiplier.
- Take Profit distance must use the same ATR value that was frozen when the trade opened.
- Example settings: 10 = TP 10 × frozen ATR away from entry; 15 = 15 × ATR; 20 = 20 × ATR.
- For SHORT trades, TP is below entry. For LONG trades, TP is above entry.
- Allow TP ATR Multiplier = 0 to mean no automatic TP, because I may close the position manually.
- If I manually close a position, the EA must not reopen from the previous signal. It must wait for a completely fresh valid 5-EMA setup.
EXECUTION / SAFETY
- Only one EA position per symbol at a time.
- Repeated ticks around the trigger must never create duplicate trades.
- No martingale and no automatic increase in position size after losses.
- Use the current MT5 chart symbol (_Symbol) rather than hard-coded symbols, so it works with broker suffixes such as BTCUSDm, XAUUSDm, USTECm and USOILm.
- After an MT5/VPS restart, the EA must detect any existing trade correctly and must never duplicate it.
INPUTS
- EMA Period = default 5
- ATR Period = default 14
- ATR SL Multiplier = default 1.0
- Risk Amount in account currency
- TP ATR Multiplier = e.g. 10 / 15 / 20 / 0 for manual exit
- Enable Long = true/false
- Enable Short = true/false
- Enable Trading = true/false
- Magic Number
ON-CHART DISPLAY
Show: Symbol, EMA value, ATR value, alert candle, trigger price, calculated SL, calculated lot size, planned monetary loss, TP and current state: WAITING / ARMED LONG / ARMED SHORT / POSITION OPEN.
DELIVERY
I require the editable .mq5 source code, compiled .ex5 file and basic instructions. It must work in MT5 Strategy Tester and Exness MT5 and must require no DLLs or external software.
One example you can also send him if he asks for clarification:
SELL entry = 30,000
ATR(14) at entry = 50 points
SL distance = 50 points → SL = 30,050
TP multiplier = 15 → TP distance = 750 points → TP = 29,250
ATR remains frozen at 50 for that entire trade.
And your AED 50 rule means the EA might deliberately risk AED 46 or AED 40 if the broker's available lot increments don't allow exactly AED 50. It should never intentionally choose AED 55/70 just to get closer to AED 50. That's worth keeping exactly as written.