ATR Trailing Stops Strategy
May 9, 2018

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.
Trading & investing are risky and many will lose money in connection with trading and investing activities. All content on this site is not intended to, and should not be, construed as financial advice. Decisions to buy, sell, hold or trade in securities, commodities and other investments involve risk and are best made based on the advice of qualified financial professionals. Past performance does not guarantee future results.
Hypothetical or Simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, including, but not limited to, lack of liquidity. Simulated trading programs in general are designed with the benefit of hindsight, and are based on historical information. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.
Testimonials appearing on this website may not be representative of other clients or customers and is not a guarantee of future performance or success.
As a provider of technical analysis tools and strategies, we do not have access to the personal trading accounts or brokerage statements of our customers. As a result, we have no reason to believe our customers perform better or worse than traders as a whole based on any content, tool, or platform feature we provide.
Charts used on this site are by TradingView in which the majority of our technical indicators are built on. TradingView® is a registered trademark of TradingView, Inc. www.TradingView.com TradingView® has no affiliation with the owner, developer, or provider of the Services described herein.
Market data is provided by CBOE, CME Group, BarChart, Massive, CoinAPI. Select U.S. equities data is provided through Massive. CBOE BZX real-time U.S. equities data is licensed from CBOE and provided through BarChart. Real-time futures data is licensed from CME Group and provided through BarChart. Select cryptocurrency data, including major coins, is provided through CoinAPI. All data is provided “as is” and should be verified independently for trading purposes.
This does not represent our full Disclaimer. Please read our full disclaimer.
© 2026 LuxAlgo Global, LLC.

