Overview
Adds a stop loss and take profit in points or ATR to any chosen trade that opens without one, checked several times a second.
- What it is
- A free Expert Advisor for MetaTrader 5, written in MQL5.
- What it does
- Adds a stop loss and take profit in points or ATR to any chosen trade that opens without one, checked several times a second.
- Shared by
- Alex
- Licence
- MIT
- Version
- 1.0 (1 Dec 2026)
- Settings
- 10 inputs
- Lab check
- Compiled with MetaEditor build 6333 for MT5 on 1 Dec 2026: 0 errors, 0 warnings.
- Price
- Free to download
Opening a trade fast from the one-click buttons or a phone often means opening it without a stop loss. This EA watches the chart's symbol and, within a second of a chosen trade appearing without a stop loss or take profit, adds them for you in points or as an ATR multiple. Existing levels are never changed.
How it works
It checks on every tick and on a timer (every 250 ms by default), so a new trade is covered even when ticks are slow.
1. For each open trade on the chart's symbol that matches Trades (all, one magic number, or only manual trades with magic 0) and is missing a stop loss, a take profit or both:
2. Distances.
- Points: stop = Stop loss points, target = Take profit points.
- ATR: stop = ATR(period) of the last closed bar on the chosen timeframe x SL multiple; target = ATR x TP multiple.
- A distance of 0 means that level is not added.
3. Levels are measured from the entry price: buy stop = entry - stop distance, buy target = entry + target distance (mirrored for a sell). They are rounded to the tick size.
4. Broker rules. If price has already moved so that a level would be closer than the broker stop level (or on the wrong side of price), the level is pushed out to the nearest allowed distance from current price. If an existing level is inside the freeze level, the trade is left until it is free.
5. Only the missing level is added; a stop or target you set yourself stays as it is. Failures are printed at most every 30 seconds and retried on the next check.
Inputs
| Input | Default | What it does |
|---|---|---|
| Trades | All trades on this symbol | All trades, only one magic number, or only manual trades (magic 0) |
| Magic number | 0 | Used when you pick "Only trades with the magic number" |
| Measure distances in | Points | Points or ATR multiple |
| Stop loss points | 300 | Stop distance in points (0 = no stop loss added) |
| Take profit points | 600 | Target distance in points (0 = no take profit added) |
| ATR timeframe | Current | Timeframe for the ATR |
| ATR period | 14 | ATR period |
| ATR SL multiple | 1.5 | Stop = ATR x this (0 = not added) |
| ATR TP multiple | 3.0 | Target = ATR x this (0 = not added) |
| Check every | 250 | Timer in milliseconds (100-1000) |
How to use it
- Copy
FXN_AutoSLTP.mq4toMQL4/Experts(MT4) orFXN_AutoSLTP.mq5toMQL5/Experts(MT5). In the terminal use File > Open Data Folder to find these folders. - Restart the terminal or right-click Expert Advisors > Refresh in the Navigator.
- Drag it onto a chart of the symbol you trade, set the inputs and allow algo trading (AutoTrading button on MT4, Algo Trading on MT5).
- A start for a 5-digit forex pair: 300-point stop and 600-point target, or ATR(14) on H1 with 1.5 and 3.0. Set the scope to "Only manual trades" if an EA on the same symbol already manages its own stops.
Good to know
- It covers the chart's symbol only; attach one copy per symbol you trade.
- There is a short moment, normally under a second, between the trade opening and the stop being added. A fast market can move in that time.
- The stop loss is added to open trades only, not to pending orders.
- The terminal must be running with algo trading allowed. On a phone-only setup run it on a VPS.
- ATR is read from the last closed bar, so the value does not change while a bar is forming.
- It does not trail or move stops later and does not open trades.
Trading carries risk. Test on a demo account first; past results do not predict future results.
Settings read from the code
| Input | Type | Default | Note |
|---|---|---|---|
| InpScope | ENUM_FXN_SCOPE | SCOPE_ALL | Trades that get a stop loss and take profit |
| InpMagic | long | 0 | Magic number (used with "Only trades with the magic number") |
| InpMode | ENUM_FXN_DIST | DIST_POINTS | Measure distances in points or ATR |
| InpSlPoints | int | 300 | Points: stop loss distance (0 = do not add a stop loss) |
| InpTpPoints | int | 600 | Points: take profit distance (0 = do not add a take profit) |
| InpAtrTimeframe | ENUM_TIMEFRAMES | PERIOD_CURRENT | ATR: timeframe |
| InpAtrPeriod | int | 14 | ATR: period |
| InpAtrSlMult | double | 1.5 | ATR: stop loss = ATR x this (0 = do not add) |
| InpAtrTpMult | double | 3.0 | ATR: take profit = ATR x this (0 = do not add) |
| InpCheckMs | int | 250 | How often to check in milliseconds (100-1000) |
How to use it
- Download the compiled file (or the source and compile it in MetaEditor).
- Put it in MetaTrader: File → Open Data Folder → MQL5 → Experts, then refresh the Navigator.
- Test it on a demo account before any real money.
- Want changes? Open a copy in your Lab and ask for them in plain words.