Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

ATR Stop Loss Take Profit Levels - indicator for MetaTrader 5

Cristhian Alexander Gaibor Cuasquer
Cristhian Alexander Gaibor Cuasquer
  • Founder & Systems Engineer at  Xander Pro
  • Ecuador
  • 9563
4.7 (40)
Trader and MQL5 member since 2017.
Views:
55
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

On Gold (XAUUSD) a fixed stop in points is too tight on a fast day and too wide on a quiet one. This indicator takes the ATR of the last closed bar and draws, right next to price, the stop loss and two targets for a buy at the ask and for a sell at the bid. Default distances are 1.5 ATR for the stop, 2 ATR for target 1 and 3 ATR for target 2.

Each level is a short line to the right of the current bar with its price and its distance in points. The stop line also shows the lot that loses 1% of the balance if that stop is hit, worked out from the tick value of the symbol. On past bars two dotted lines show where that ATR stop sat for a buy and for a sell.

The levels follow price on every tick, so they are a guide for the order you are about to place, not a signal. The lot is rounded down to the volume step and is not shown when it is below the minimum lot.

ATR Stop Loss Take Profit Levels on a XAUUSD M15 chart in MetaTrader 5: buy and sell stop loss and two take profit levels from the ATR with the lot for 1 percent risk

Settings

  • ATR period: default 14, read on the last closed bar.
  • Stop loss distance: 1.5 x ATR. Take profit 1: 2.0 x ATR. Take profit 2: 3.0 x ATR. A target set to 0 is not drawn.
  • Levels for: buy and sell, buy only or sell only.
  • Risk per trade: 1% of the balance, 0 hides the lot.
  • ATR stop lines on past bars: on. Close minus and plus the stop distance on every closed bar, bars 1000 (0 = all).
  • Length of the level lines: 8 bars to the right, buy and sell colours, text colour and font size.
  • Object prefix: change it to run two copies on the same chart.

What it needs

Any symbol and any timeframe. It reads the built-in ATR and the symbol tick value, tick size, volume step and minimum and maximum lot from your broker. The dotted lines are buffers 0 (buy stop) and 1 (sell stop), so an EA can read them with iCustom. It never trades.

Make it yours

Run it on XAUUSD, XAGUSD, EURUSD, GBPUSD, US30 or NAS100 and compare the ATR stop on M5, M15 and H1 with the stop you use today. Put the stop beyond a Smart Money Concepts order block or a support and resistance level and check how many ATR it really is. XP_RiskLot is a small function you can copy into any EA to size the lot from the stop distance, and the multipliers can be tied to a session filter.

About this code

Open source. Use it as it is, adapt it, build your own version on top of it. Questions, suggestions and your own tests are welcome in the comments below. Provided as is, use at your own risk.

Related: Risk Lot Size Calculator Panel, Trailing Stop Breakeven Manager, Supertrend Gold Signals, Partial Close Multi TP Manager.

Changelog

v1.0 (2026-12-05): initial release.

Monte Carlo Drawdown from Your Account History, with Capital Check Monte Carlo Drawdown from Your Account History, with Capital Check

Shuffles your closed trades thousands of times to show how deep the drawdown can realistically get (p50/p95/p99), and checks whether your account size can carry it. Reads the account history or a CSV file and writes a readable HTML report.

OnTester Robustness Score with Simulated Commission and Trade CSV Export OnTester Robustness Score with Simulated Commission and Trade CSV Export

A custom OnTester() criterion that ranks optimisation passes by net profit factor, number of trades, drawdown and equity-curve linearity. Includes simulated commission, trade export to CSV and a readable HTML report.

Pivot Points Daily Weekly Monthly Pivot Points Daily Weekly Monthly

Pivot points for Gold (XAUUSD) and any symbol on MT5. Classic or Fibonacci P, R1 to R3 and S1 to S3 from the previous day, week or month, one set per period, with an optional alert when a candle closes across a level. Open source code.

Spread Monitor Alert Spread Monitor Alert

Spread monitor for Gold (XAUUSD) and any symbol on MT5. Shows the spread now, its average and the highest of the day in a small panel and alerts when the spread opens above your limit or above twice the average. Open source code.