This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
24 lines of Pine Script v5 from tv-scripts/tvt_atr_stoploss.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
tvt_atr_stoploss.pine
//@version=5
indicator("[TVT] ATR Trailing Stoploss", overlay = true)
Atr = input.int(defval = 5, title = "Atr Period", minval = 1, maxval = 500)
Hhv = input.int(defval = 10, title = "HHV Period", minval = 1, maxval = 500)
Mult = input.float(defval = 2.5, title = "Multiplier", minval = 0.1)
Barcolor = input.bool(true, title = "Barcolor")
Prev = ta.highest(high - Mult * ta.atr(Atr), Hhv), ta.barssince(close > ta.highest(high - Mult * ta.atr(Atr), Hhv) and close > close[1])
TS = ta.cum(1) < 16 ? close : close > ta.highest(high - Mult * ta.atr(Atr), Hhv) and close > close[1] ? ta.highest(high - Mult * ta.atr(Atr), Hhv) : Prev
Color = close > TS ? color.green : close < TS ? color.red : color.black
barcolor(Barcolor ? Color : na)
plot(TS, color = Color, linewidth = 3, title = "ATR Trailing Stoploss")
Buy = ta.crossover(close, TS)
Sell = ta.crossunder(close, TS)
plotshape(Buy, "BUY", shape.labelup, location.belowbar, color.green, text = "BUY", textcolor = color.black)
plotshape(Sell, "SELL", shape.labeldown, location.abovebar, color.red, text = "SELL", textcolor = color.black)
alertcondition(Buy, "Buy Signal", "Buy ATR Trailing Stoploss")
alertcondition(Sell, "Sell Signal", "Sell ATR Trailing Stoploss")
Overview
ATR Trailing Stoploss plots the trailing stop line directly on the price chart and colors price bars based on whether the close is above or below the line. It generates buy signals when price crosses above the trailing stop and sell signals when price crosses below it, plotting labels and triggering alert conditions. Users can configure the ATR period, lookback period, ATR multiplier, and bar coloring.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Atr Period
int
5
Atr
HHV Period
int
10
Hhv
Multiplier
float
2.5
Mult
Barcolor
bool
true
Barcolor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This indicator plots an ATR-based Chandelier Exit trailing stop on the price chart. It tracks a long stop under recent highs and a short stop above recent lows, then switches direction when price crosses the opposite stop. Buy and sell labels mark those flips.
The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha
Range Filter [Alorse] is a technical indicator overlay for TradingView designed to filter market volatility and identify price trends. It calculates a smoothed range based on historical volatility using a configurable sampling period and multiplier applied to
This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre
This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high
An overlay indicator that combines an ATR-based SuperTrend trailing stop with an integrated RSI-derived midline calculation on the price chart. The SuperTrend uses an ATR period and factor multiplier to plot dynamic green or red trend lines based on price dire