ATR + Trailing Stops

What it does

  • Displays trailing ATR (Average True Range).
  • Displays current ATR.
  • Alerts when price crosses the trailing ATR.

The script has two modes: Running and Trailing. In Running mode, it continuously displays the ATR above and below the price. Specifically, it displays the High and Low price plus and minus the ATR times a user-supplied multiplier. This can be helpful for visualising volatility.

In Trailing mode, it displays the same ATR line, except the line trails until price crosses it. When price crosses it, it flips from long to short or vice-versa.

Why it’s great

It’s great because:

  • It’s simple. You can use it immediately with the standard settings.
  • It’s configurable. You can adjust it exactly how you want it.
  • It has both long and short trailing stops, and switches automatically.

It also has an alert condition included:

  • Price crossed ATR: Alerts when price crosses the trailing ATR (long or short; whichever one is active). You can set this to trigger Once, or Once per bar close, in the TradingView alert configuration screen. You can use this for soft stops or to look for entries.

A unique feature is the ability to tune how much weight to give to candle wicks and bodies in the ATR calculation. I haven’t seen this anywhere else.

How to get it

Click this button from the script page on TradingView: Add to favorite Scripts button in TradingView

Limitations

It works on all markets and timeframes. On lower timeframes there will obviously be more chop.

How to trade with it

The main usage of this indicator is to use trailing ATR as a stop loss. Adjust the multiplier and lookback period for your asset and preference.

While you *could* enter and exit trades just on breaks of ATR, that’s not what it’s intended for. You’ll want to use other elements to qualify your entries.

Settings

These are all the user-configurable settings and what they do.

  • ATR Lookback Period – The number of bars to go back and include in the ATR calculation. You don’t normally need to change this, but you can do in order to make ATR more or less responsive.
  • ATR Multiplier – The ATR is multiplied by this number before being added to price. You definitely need to experiment with this value for your chosen asset and timeframe.
  • Trail Mode – Switch between displaying running and trailing ATR.
  • Flip Trail on – Set what counts as “hitting” the ATR line: either a candle wick or a candle close. You might use wick for hard stops and close for soft stops.

Advanced settings:

  • Percentage of Body to Include – To emulate the standard ATR, leave this and the wick percentage both at 100. To give greater weight to candle bodies, increase this and decrease the wick percentage.
  • Percentage of Wick to Include – To emulate the standard ATR, leave this and the body percentage both at 100. To give greater weight to wicks, increase this and decrease the body percentage. Using wick-based ATR tends to keep it closer to price when there’s a large move. Experiment for your trading style.
  • ATR Smoothing Mode – The TradingView built-in ATR function uses RMA as a smoothing method. This gives you the option to choose RMA, SMA, EMA, or WMA.

Credits

Original concept for plotting multiples of running ATR on a chart from a script “Trailing Stop Loss Multiple of ATR” by @Bluephantom, modified by RickSanchex.

Completely rewritten and extended by @SimpleCryptoLife to include trailing option and made compatible with PineScript v4. The function for applying different moving averages based on user input is from the TradingView ATR template.

Support and questions

For any questions about using this indicator, or to report a bug, please leave a comment on the script page on TradingView rather than sending a message.

Technical details

This indicator does not repaint, meaning, it doesn’t go back and alter any bars in the past. However, until a candle closes, the indicator can only use the current price, and so the drawings, colours and warnings for the current candle (including any lines that join the current candle to the previous one) will change as the price changes. Once the candle closes, they are fixed.

🌍 Share this:

Get an email when I release new stuff.