All indicators

Custom ATR Trailing Stop

Jul 18, 2024

Static chart image
SignalsTrailing-StopVolatility

The Custom ATR Trailing Stop indicator provides a dynamic stop-loss management system that adjusts to market volatility and price movement starting from a user-defined entry point.

Usage

The Usage section describes how the script can be used. This tool is designed to manage active trades by providing a visual and functional trailing stop-loss. To use the indicator, the user must first define a "Bar Time" which identifies the exact candle where a trade was initiated. Once the starting point is set, the indicator calculates and plots the trailing stop level based on the selected direction (Long or Short).

The script offers two primary methods for trailing:

  • ATR Mode: The stop-loss is calculated using a multiple of the Average True Range. This allows the stop to widen during high volatility and tighten during low volatility.
  • Percentage Mode: The stop-loss is set at a fixed percentage distance from the signal source (e.g., 2% below the current high for a long trade).

A key feature is the "Breakeven" logic. When using ATR mode, users can define a secondary multiplier or a manual price level. Once the price moves favorably beyond this threshold, the script can tighten the stop-loss to protect capital or lock in gains.

Details

The script executes by first calculating the Average True Range (ATR) and smoothing it with a Simple Moving Average (SMA). When the specified "Bar Time" matches the chart time, the "Trade State" becomes active.

The trailing logic is "one-way," meaning for a long trade, the stop-loss level can only move upward. If the price moves favorably, the indicator recalculates the distance from the price source; if the new calculation is higher than the previous level, the stop is updated. If the price moves against the trade, the stop level remains stationary until hit. The script includes built-in alert conditions for trade entry, stop-loss triggers, and price crossovers.

Settings

Trade Setup

  • Bar Time: Determines the specific candle where the trade calculation begins.
  • Trade Direction: Sets the trade type to either Long or Short.
  • Long/Short Signal Source: Defines the price data (Close, Open, High, etc.) used for stop calculations.
  • Trailing Method: Switches between "ATR" and "Percent" calculation logic.

Trailing Method - Average True Range

  • ATR Lookback: The number of bars used to calculate the ATR.
  • ATR average Lookback: The period for the SMA smoothing applied to the ATR value.
  • Initial ATR Multiplier: The multiplier used to set the stop distance at the start of the trade.
  • Breakeven ATR Multiplier: The multiplier used once the price reaches the breakeven threshold.
  • Manual Breakeven Level: An optional fixed price level to trigger breakeven logic. If set to zero, the entry candle's close is used.

Trailing Method - Percentage

  • Signal Source Percentage: The fixed percentage distance used for the trailing stop when in "Percent" mode.

FAQ

How do I start the trailing stop on a specific candle?
You can set the starting point by adjusting the "Bar Time" setting in the inputs menu or by using the "confirm" feature when first adding the script to the chart.

What do the different colors on the trailing stop line mean?
A green line indicates that the current stop-loss level is in a "profitable" zone relative to your entry price, while a red line indicates the stop-loss is still in an "unprofitable" zone (potential loss).

How can I access the Custom ATR Trailing Stop?
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.