All indicators

ATR Trailing Stops Strategy

May 9, 2018

Static chart image
Dynamic OverlaysSignalsTrailing-StopVolatility

The ATR Trailing Stops Strategy indicator provides an automated backtesting framework for trend-following based on volatility-adjusted stop levels. It aims to identify trend reversals by tracking price action relative to an Average True Range (ATR) boundary, allowing traders to evaluate the efficacy of trailing stops across different market conditions.

Usage

The Usage section describes how the script can be used to identify entry and exit points. The strategy primarily functions as a trend-following mechanism where the trailing stop line acts as a dynamic support or resistance level.

  • Long Entries: A long position is initiated when the closing price crosses above the ATR trailing stop line. This suggests a shift from a bearish to a bullish regime.
  • Exits and Shorts: When the price crosses below the trailing stop line, the strategy closes the long position. If the "Test w/Shorts?" option is enabled, the script will simultaneously open a short position.
  • Time-Filtered Backtesting: Users can isolate specific historical periods for performance analysis. For example, setting "Max Days Back" to 360 and "Min Days Back" to 180 will restrict the strategy execution to a window between one year and six months ago.

Details

The strategy calculates the trailing stop based on the Average True Range (ATR) multiplied by a user-defined factor. Unlike a standard moving average, the ATR trailing stop is designed to stay below the price during an uptrend and above the price during a downtrend, only flipping when a significant price crossover occurs.

The logic ensures that during a sustained uptrend, the stop level can only move upward (ratchet effect) to lock in profits, and during a downtrend, it can only move downward. The calculation uses the math.max and math.min functions to prevent the stop from retreating against the trade direction until a trend reversal is confirmed by a price cross.

Settings

  • ATR Period: Defines the lookback window used to calculate market volatility via the Average True Range.
  • ATR Multiplier: Determines the distance between the price and the trailing stop line. A higher multiplier provides more "room" for the trade but may result in larger drawdowns.
  • Test w/Shorts?: A toggle to determine if the strategy should flip into short positions upon a bearish cross or simply move to a cash (flat) position.
  • Max Days Back to Test: Sets the starting point of the backtest relative to the current time (in days). Setting this to 0 includes all available historical data.
  • Min Days Back to Test: Sets the end point of the backtest relative to the current time (in days). Setting this to 0 allows the strategy to run up to the most recent bar.

FAQ

How do I adjust the sensitivity of the trend detection? You can adjust the ATR Period or the ATR Multiplier. Lowering these values makes the strategy more sensitive to price changes, potentially leading to more frequent trades, while increasing them filters out minor price fluctuations.

Can I use this strategy for intraday trading? Yes, the strategy can be applied to any timeframe. However, you should adjust the ATR settings and time-back filters to suit the specific volatility profile of the intraday chart you are trading.

How do I get access to the ATR Trailing Stops Strategy? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.