All indicators

Simple Trailing Buy & Stop Strategy

Jul 23, 2018

Static chart image
SignalsMoving AveragesTrailing-StopVolatility

The Simple Trailing Buy & Stop Strategy tool provides a backtesting framework for percentage-based trailing entries and exits to help traders automate trade timing based on price volatility.

Usage

The strategy is designed for trend-following and momentum trading. Users can define specific percentage offsets to determine when the price has moved significantly enough to warrant an entry or an exit. For example, on higher timeframes like the Daily chart, using a wider stop offset (e.g., 4.3%) and a narrower buy offset (e.g., 1.9%) can help filter out minor price fluctuations while capturing major trends. On lower timeframes like the 4-hour, tighter stop offsets such as 1.5% may be more effective in protecting capital against intraday volatility.

The script visualizes two primary lines on the chart:

  • Trailing Buy: A dynamic level plotted above the average price. A long position is initiated when the designated price trigger crosses above this line.
  • Trailing Stop: A dynamic level plotted below the average price. An active position is closed when the designated price trigger crosses below this line.

Details

The core of the strategy relies on a Relative Moving Average (RMA) calculation to establish a smoothed baseline for price action.

  • Entry Logic: The entry level is calculated by taking the RMA of the source and adding the user-defined Buy Offset percentage. This ensures the price must demonstrate sufficient upward momentum before a trade is opened.
  • Exit Logic: The exit level is calculated by taking the RMA of the source and subtracting the user-defined Stop Offset percentage. This creates a trailing floor that moves upward as the average price increases.

By utilizing the "High" for buy triggers and the "Low" for stop triggers by default, the strategy accounts for the full price range of a candle, ensuring that spikes or dips through the levels are captured immediately.

Settings

  • Stop Offset %: Determines the percentage distance below the average price where the trailing stop loss level is placed.
  • Trailing Buy Offset %: Determines the percentage distance above the average price where the trailing buy entry level is placed.
  • Use last x bars for calculation: The lookback period (length) used for the Relative Moving Average (RMA) calculation.
  • Source Trailing Stop calculation: The price source (e.g., Close) used to compute the smoothed average for the stop level.
  • Source Trailing Buy calculation: The price source used to compute the smoothed average for the entry level.
  • Source Stop Trigger: The price source (e.g., Low) checked against the trailing stop level to trigger a sell signal.
  • Source Buy Trigger: The price source (e.g., High) checked against the trailing buy level to trigger a buy signal.

FAQ

How does the strategy adapt to different market conditions? The strategy is highly customizable via the percentage offsets. In high-volatility markets, traders typically increase the offset percentages to avoid premature exits, whereas in low-volatility trending markets, tighter offsets can be used to lock in profits.

What is the benefit of using an RMA instead of a standard SMA? The Relative Moving Average (RMA) provides a smoothing effect similar to an Exponential Moving Average, giving more weight to recent data which allows the trailing levels to react more fluidly to recent price shifts compared to a Simple Moving Average.

How do I access the Simple Trailing Buy & Stop 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.