Scripts / ATR Trailing Stop

ATR Trailing Stop

Free (planned) Indicator

Draws a trailing stop a multiple of ATR away from price. In “Both” mode the trail flips from long to short (or short to long) when a close crosses it. Long-only and short-only modes keep one side of the trail and can alert when a close crosses it. The trail only tightens while a side is active; it does not loosen. This is a chart tool, not a trading system.

Free access is planned. On this preview the source is here so you can paste it into TradingView and confirm it compiles. Nothing has been published to TradingView or to the live domain.

Screenshot placeholder
Screenshot coming later. After the script is pasted into TradingView and compiles, capture the chart, the settings panel, and the alert list. Do not use Strategy Tester profit or win-rate figures on this page.

What it does

Draws a trailing stop a multiple of ATR away from price. In “Both” mode the trail flips from long to short (or short to long) when a close crosses it. Long-only and short-only modes keep one side of the trail and can alert when a close crosses it. The trail only tightens while a side is active; it does not loosen. This is a chart tool, not a trading system.

Works on any chart. A common starting point is ATR length 14 and multiplier 3.0.

Settings

ATR lengthDefault 14. Uses TradingView’s Wilder ATR (ta.atr).
ATR multiplierDefault 3.0. The trail sits this many ATRs from the chosen source.
Measure the trail from“High / Low” (chandelier-style: long from the high, short from the low) or “Close.”
DirectionBoth (flip when crossed), long trail only, or short trail only.
Wait for the bar to closeOn by default. A flip or a trail-hit mark waits until the candle confirms.
Display and alertsOptional fill, labels, status table, and alerts for a flip or a crossed trail.

How to add it in TradingView

  1. Open TradingView and open any chart.
  2. Open the Pine Editor at the bottom of the window.
  3. Copy the source file atr_trailing_stop.pine, paste it into the editor (replace whatever is there), then Save and Add to chart.
  4. Start with length 14 and multiplier 3.0, then adjust in Settings.
  5. Leave “Wait for the bar to close before a flip or a hit” on so a flip or a hit is only marked after the candle confirms.
  6. Optional: create an alert and pick a flip condition or a “trail was crossed” condition.

Notes, including backtests

This is an indicator, not a strategy, so it has no Strategy Tester results to report. It has had a careful manual review for Pine Script v6, but it has not been compiled in TradingView yet. After you paste it, if TradingView shows an error, copy the exact message and the script can be fixed before anything is published. Nothing on this page is a claim that a trailing stop improves results.

Educational tool, not financial advice. This script is not a signal service and it does not place orders. It does not promise profits, win rates, or trading results.