Indicator · Pine Script v6 · On the chart

Aroon Trend Trail [BackQuant]

by theonetrade· code credited to BackQuant

The Aroon Trend Trail [BackQuant] indicator overlays an adaptive trailing stop rail directly on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code144
Settings14inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

144 lines of Pine Script v6 from assets/indicator/bit-exact/aroon_trend_trail_backquant_30BBpKLx.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

aroon_trend_trail_backquant_30BBpKLx.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BackQuant

//@version=6
indicator("Aroon Trend Trail [BackQuant]", shorttitle="Aroon Trail [BackQuant]", overlay=true)

// Constants
const string calc = "Aroon Calculation"
const string rail = "Trend Rail Settings"
const string ui = "Plotting and Coloring"
const color GREEN = #00ff00
const color RED = #ff0000

// Inputs
int aroonLen = input.int(25, "Aroon Length", minval=2, group=calc)
float flipThreshold = input.float(0.15, "Bias Threshold", minval=0.0, maxval=1.0, step=0.01, group=calc, tooltip="Minimum Aroon bias required to establish the opposite trend.")

int atrLen = input.int(14, "ATR Length", minval=1, group=rail, inline="ATR")
float atrFactor = input.float(1.8, "Base Width", minval=0.1, step=0.05, group=rail, inline="ATR")
float strongWidth = input.float(0.65, "Strong Trend Width", minval=0.1, maxval=3.0, step=0.05, group=rail, inline="WIDTH")
float weakWidth = input.float(1.25, "Weak Trend Width", minval=0.1, maxval=3.0, step=0.05, group=rail, inline="WIDTH")
bool breakOnFlip = input.bool(true, "Break Rail On Flips", group=rail)

color longCol = input.color(GREEN, "Bullish", group=ui, inline="COL")
color shortCol = input.color(RED, "Bearish", group=ui, inline="COL")
int lineW = input.int(3, "Line Width", minval=1, maxval=6, group=ui)
bool showFill = input.bool(true, "Gradient Fill", group=ui)
bool showGlow = input.bool(true, "Rail Glow", group=ui)
bool showAroon = input.bool(false, "Show Aroon Values", group=ui)
bool paintCandles = input.bool(true, "Color Candles", group=ui)

// Aroon
int sinceHigh = math.abs(ta.highestbars(high, aroonLen))
int sinceLow = math.abs(ta.lowestbars(low, aroonLen))

float aroonUp = 100.0 * (aroonLen - sinceHigh) / aroonLen
float aroonDown = 100.0 * (aroonLen - sinceLow) / aroonLen

float aroonBias = (aroonUp - aroonDown) / 100.0
float aroonStrength = math.min(math.abs(aroonBias), 1.0)

// Trend State
var int trend = 0

if trend == 0
    trend := aroonBias >= 0.0 ? 1 : -1
else if trend != 1 and aroonBias > flipThreshold
    trend := 1
else if trend != -1 and aroonBias < -flipThreshold
    trend := -1

bool bullFlip = trend == 1 and trend[1] == -1
bool bearFlip = trend == -1 and trend[1] == 1
bool trendFlip = bullFlip or bearFlip

color trendCol = trend == 1 ? longCol : shortCol

// Adaptive Rail Width
float atr = ta.atr(atrLen)
float widthScale = weakWidth + (strongWidth - weakWidth) * aroonStrength
float railWidth = atr * atrFactor * widthScale

float rawLower = hl2 - railWidth
float rawUpper = hl2 + railWidth

// Ratcheting Rail
var float lowerRail = na
var float upperRail = na

if na(lowerRail)
    lowerRail := rawLower
    upperRail := rawUpper
else
    if trend == 1
        lowerRail := bullFlip ? rawLower : math.max(lowerRail[1], rawLower)
    else
        lowerRail := rawLower

    if trend == -1
        upperRail := bearFlip ? rawUpper : math.min(upperRail[1], rawUpper)
    else
        upperRail := rawUpper

float activeRail = trend == 1 ? lowerRail : upperRail
float plottedRail = breakOnFlip and trendFlip ? na : activeRail

// Visual Strength
float railDistance = math.abs(close - activeRail)
float distanceStrength = railWidth > 0.0 ? math.min(railDistance / railWidth, 1.0) : 0.0
float trendStrength = math.min(aroonStrength * 0.75 + distanceStrength * 0.25, 1.0)

int strengthBoost = int(math.round(trendStrength * 14.0))

// Gradient
bool fillReady = showFill and not na(plottedRail)
bool priceAbove = close >= activeRail

float grad1 = activeRail + (close - activeRail) * 0.15
float grad2 = activeRail + (close - activeRail) * 0.35
float grad3 = activeRail + (close - activeRail) * 0.60
float grad4 = activeRail + (close - activeRail) * 0.82

pRail = plot(plottedRail, "Aroon Trend Rail", trendCol, lineW, plot.style_linebr)
pPrice = plot(fillReady ? close : na, "Price Ref", display=display.none, editable=false)
pGrad1 = plot(fillReady ? grad1 : na, "Gradient Ref 1", display=display.none, editable=false)
pGrad2 = plot(fillReady ? grad2 : na, "Gradient Ref 2", display=display.none, editable=false)
pGrad3 = plot(fillReady ? grad3 : na, "Gradient Ref 3", display=display.none, editable=false)
pGrad4 = plot(fillReady ? grad4 : na, "Gradient Ref 4", display=display.none, editable=false)

fill(pRail, pGrad1, priceAbove ? grad1 : activeRail, priceAbove ? activeRail : grad1, fillReady ? color.new(trendCol, 82) : na, fillReady ? color.new(trendCol, math.max(28, 55 - strengthBoost)) : na, title="Gradient Layer 1")
fill(pGrad1, pGrad2, priceAbove ? grad2 : grad1, priceAbove ? grad1 : grad2, fillReady ? color.new(trendCol, 90) : na, fillReady ? color.new(trendCol, 68) : na, title="Gradient Layer 2")
fill(pGrad2, pGrad3, priceAbove ? grad3 : grad2, priceAbove ? grad2 : grad3, fillReady ? color.new(trendCol, 94) : na, fillReady ? color.new(trendCol, 79) : na, title="Gradient Layer 3")
fill(pGrad3, pGrad4, priceAbove ? grad4 : grad3, priceAbove ? grad3 : grad4, fillReady ? color.new(trendCol, 97) : na, fillReady ? color.new(trendCol, 88) : na, title="Gradient Layer 4")
fill(pGrad4, pPrice, priceAbove ? close : grad4, priceAbove ? grad4 : close, fillReady ? color.new(trendCol, 99) : na, fillReady ? color.new(trendCol, 95) : na, title="Gradient Layer 5")

// Glow
float glow = atr * (0.045 + trendStrength * 0.025)
float outerGlow = glow * 2.3

pGlowOuterLower = plot(showGlow ? activeRail - outerGlow : na, "Outer Glow Lower", display=display.none, editable=false)
pGlowOuterUpper = plot(showGlow ? activeRail + outerGlow : na, "Outer Glow Upper", display=display.none, editable=false)
pGlowLower = plot(showGlow ? activeRail - glow : na, "Glow Lower", display=display.none, editable=false)
pGlowUpper = plot(showGlow ? activeRail + glow : na, "Glow Upper", display=display.none, editable=false)

fill(pGlowOuterLower, pGlowOuterUpper, showGlow ? color.new(trendCol, 95) : na, title="Outer Rail Glow")
fill(pGlowLower, pGlowUpper, showGlow ? color.new(trendCol, math.max(60, 84 - strengthBoost)) : na, title="Inner Rail Glow")

// Candles
plotcandle(open, high, low, close, "Trend Candles", trendCol, trendCol, true, bordercolor=trendCol, display=paintCandles ? display.all : display.none)

// Data Window
plot(aroonUp, "Aroon Up", display=display.data_window)
plot(aroonDown, "Aroon Down", display=display.data_window)
plot(aroonBias, "Aroon Bias", display=display.data_window)
plot(aroonStrength * 100.0, "Aroon Strength", display=display.data_window)
plot(railWidth, "Active Rail Width", display=display.data_window)

plot(showAroon ? aroonUp : na, "Aroon Up Diagnostic", display=display.data_window)
plot(showAroon ? aroonDown : na, "Aroon Down Diagnostic", display=display.data_window)

// Alerts
alertcondition(bullFlip, "Aroon Rail Bullish", "Aroon Trend Rail turned bullish on {{ticker}}")
alertcondition(bearFlip, "Aroon Rail Bearish", "Aroon Trend Rail turned bearish on {{ticker}}")
alertcondition(trendFlip, "Aroon Rail Flip", "Aroon Trend Rail changed direction on {{ticker}}")

Overview

Aroon Trend Trail [BackQuant] calculates trend direction and strength using the Aroon indicator over a customizable period. Combining ATR volatility with Aroon strength scaling, it dynamically adjusts rail width and ratchets the active rail level during sustained movements. Users can customize Aroon thresholds, ATR parameters, width scaling factors, line visual properties, candle coloring, and visual glow or fill options.

Details

Published by

theonetrade on GitHub

Code credit

BackQuant, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Aroon Lengthint25aroonLen
Bias Thresholdfloat0.15flipThreshold
ATR Lengthint14atrLen
Base Widthfloat1.8atrFactor
Strong Trend Widthfloat0.65strongWidth
Weak Trend Widthfloat1.25weakWidth
Break Rail On FlipsbooltruebreakOnFlip
BullishcolorGREENlongCol
BearishcolorREDshortCol
Line Widthint3lineW
Gradient FillbooltrueshowFill
Rail GlowbooltrueshowGlow
Show all 14 settings
SettingTypeDefaultVariable
Show Aroon ValuesboolfalseshowAroon
Color CandlesbooltruepaintCandles
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.

Similar Pine Scripts

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

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup
257 stars

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

Indicator v5 TrendVolatility & bands
Updated 2 months ago · None stated GitHub repository of SuperTrend ATR + RSI
114 stars

ADX Strategy (original) is an overlay indicator that identifies trend-following trade signals using the Average Directional Index (ADX) combined with a Simple Moving Average filter. A long signal is generated when the ADX rises above a user-defined trend level

Indicator v4 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of ADX Strategy (original)

Moon Dev Lunar Sniper

by moondevonyt
98 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Lunar Sniper
57 stars

Double Screened Decision is a multi-timeframe trend and momentum indicator overlaid directly on the price chart. It dynamically selects a higher timeframe based on the active chart resolution to evaluate higher-timeframe MACD, Bollinger Bands, RSI, and Stochas

Indicator v5 TrendMoving averages Repaints
Updated 4 months ago · None stated GitHub repository of Double Screened Decision
55 stars

The VibeTrader Signal System is an overlay indicator that identifies trend direction and potential reversal conditions. It calculates a Supertrend line alongside Bollinger Bands and a 14-period RSI indicator. The script highlights bullish and bearish trends by

Indicator v6 TrendVolatility & bands
Updated 7 months ago · Apache-2.0 GitHub repository of VibeTrader Signal System

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers