Trailing SL Strategy
Feb 26, 2020

The Trailing SL Strategy tool provides a systematic approach to trend-following by using a single, dynamic trailing stop loss to determine market direction and execute immediate position reversals.
Usage
The Usage section describes how the script can be used to capture market trends through automated stop-execution. The strategy operates on a continuous "always-in-the-market" basis; once the price breaches the trailing stop loss line, the current position is closed and a new position in the opposite direction is opened.
Users can choose between three distinct calculation methods for the stop loss:
- Percentage (%): The stop loss is placed at a fixed percentage away from the current price.
- Average True Range (ATR): The stop loss adapts to market volatility, calculated as the ATR multiplied by a specific coefficient.
- Absolute: The stop loss is placed at a fixed price distance from the current price.
For example, a trader looking to capture long-term trends might use the ATR setting to allow for wider stops during volatile periods, while a scalper might prefer a tight Percentage-based stop to exit quickly when momentum shifts.
Details
The strategy logic, originally developed by QuantNomad, is built around the concept of price action relative to a trailing boundary. For long positions, the trailing stop loss is calculated as the low - slVal, but it is designed to only move upward (taking the maximum of the previous SL and the new calculation) to lock in profits. Conversely, for short positions, the stop is calculated as high + slVal and only moves downward (taking the minimum of the previous SL and the new calculation).
When the price crosses the trailing stop line:
- A reversal signal is generated.
- The calculation of the stop loss flips to the opposite side of the price.
- The strategy enters a new trade (Long if price broke above the SL, Short if price broke below).
Settings
The settings are categorized to allow for precise control over the risk management and the backtesting period:
- SL Type: Selects the mathematical foundation for the trailing stop (%, ATR, or Absolute).
- % SL: Defines the percentage distance for the stop loss when "%" is selected.
- ATR Length: Sets the lookback period used to calculate the Average True Range.
- ATR Mult: The multiplier applied to the ATR value to determine the stop distance.
- Absolute SL: Sets a fixed point/price distance for the stop loss.
- Backtesting Range: A group of settings (From Day/Month/Year to To Day/Month/Year) that defines the specific window of historical data where the strategy will execute trades.
FAQ
How does the strategy handle "whipsaws" or sideways markets? Because this is a reversal strategy that is always in a position, sideways markets may result in multiple consecutive stop-outs. Users should adjust the SL Type and values to filter out minor price fluctuations.
Can I use this for alerts without trading? Yes, the script includes visual plots and built-in alert conditions for Long and Short signals that can be used for manual trading or external notifications.
How do I access the Trailing SL Strategy? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Unlock Unlimited Access to the LuxAlgo Library
Upgrade your plan to get all indicators, strategies, charts, and full access to Quant, our AI agent.
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.

