OPEN-SOURCE SCRIPT

Aroon Trend Trail [BackQuant]

2 847
Aroon Trend Trail [BackQuant]

Overview
Aroon Trend Trail is a trend overlay that uses the relative recency of recent highs and lows to determine direction, then plots an ATR-based trailing rail whose width changes with the strength of the Aroon bias.

The indicator has two separate parts:

  • Aroon state: determines whether the trend is bullish or bearish.
  • Trend rail: provides a ratcheting lower or upper boundary based on ATR.


The rail itself does not determine trend changes. Bullish and bearish flips come from the Aroon bias crossing the selected Bias Threshold.

Aroon Calculation
The script measures how many bars have passed since the highest high and lowest low inside the selected Aroon Length.

It then calculates:

  • Aroon Up = 100 × (Length - Bars Since Highest High) / Length
  • Aroon Down = 100 × (Length - Bars Since Lowest Low) / Length


A recent high produces a high Aroon Up value.

A recent low produces a high Aroon Down value.

Because the script searches the current bar plus the previous Length - 1 bars, the calculated values approach the usual 0–100 Aroon scale but do not reach exactly zero within a complete window.

Aroon Bias
The two values are combined into:

  • Aroon Bias = (Aroon Up - Aroon Down) / 100


Positive values mean the recent-high component is stronger.

Negative values mean the recent-low component is stronger.

The absolute value of the bias is used as Aroon Strength:

  • Aroon Strength = |Aroon Bias|


This measures the separation between Aroon Up and Aroon Down, not trend direction.

Trend State
The trend state is persistent rather than changing every time the bias crosses zero.

On initialization:

  • Bias >= 0 = bullish.
  • Bias < 0 = bearish.


After that, a bullish trend requires:

  • Aroon Bias > Bias Threshold


and a bearish trend requires:

  • Aroon Bias < -Bias Threshold


This creates a neutral zone between the two thresholds.

For example, with a Bias Threshold of 0.15:

  • Above +0.15 can establish bullish state.
  • Below -0.15 can establish bearish state.
  • Between those values, the previous trend state is retained.


This reduces repeated trend changes when Aroon Up and Aroon Down are close together.

Bias Threshold
Lower values make the trend state easier to reverse.

Higher values require a larger difference between Aroon Up and Aroon Down before the opposite trend can be established.

This setting affects only the trend-state logic.

ATR Trend Rail
Once the trend state is known, the indicator creates an upper and lower raw rail around HL2.

The base width is:

  • ATR × Base Width × Width Scale


ATR controls the current market-range component.

The Width Scale is determined by Aroon Strength.

Adaptive Rail Width
The scale is interpolated between the Weak Trend Width and Strong Trend Width:

  • Width Scale = Weak Width + (Strong Width - Weak Width) × Aroon Strength


With the default settings:

  • Weak Aroon separation uses a wider rail.
  • Strong Aroon separation uses a narrower rail.


This happens because the default Strong Trend Width is smaller than the Weak Trend Width.

The inputs are fully configurable, so changing their relationship can change that behaviour.

Raw Rail Levels
The raw boundaries are:

  • Lower Rail = HL2 - Rail Width
  • Upper Rail = HL2 + Rail Width


These raw levels are then converted into one-sided trailing rails.

Ratcheting Behaviour
During a bullish trend, the Lower Rail becomes active.

It can:

  • Move upward.
  • Remain unchanged.


but it does not move downward while the bullish state remains active.

The calculation uses:

  • max(Previous Lower Rail, Current Raw Lower Rail)


During a bearish trend, the Upper Rail becomes active.

It can:

  • Move downward.
  • Remain unchanged.


but it does not move upward while the bearish state remains active.

The calculation uses:

  • min(Previous Upper Rail, Current Raw Upper Rail)


When the trend flips, the newly active rail is reset to the current raw level.

Important: Rail Crosses Do Not Flip the Trend
Price crossing the rail does not directly change the bullish or bearish state.

The trend changes only when the Aroon Bias passes the opposite Bias Threshold.

The rail should therefore be interpreted as a trailing visual boundary associated with the current Aroon regime, not as the trigger used to create that regime.

Break Rail On Flips
When enabled, the plotted rail is hidden on the exact trend-flip bar.

This prevents TradingView from drawing a connecting segment between the old rail on one side of price and the newly reset rail on the other.

This is visual only and does not affect the calculation.

Visual Strength
The script calculates a separate strength value used for the gradient and glow.

It combines:

  • 75% Aroon Strength.
  • 25% distance between Close and the active rail, normalized by Rail Width.


This Visual Strength does not change:
  • Trend direction.
  • Aroon Bias.
  • Rail position.
  • Signals.


It only changes the intensity of the visual effects.

Gradient Fill
The optional gradient fills the space between the active rail and Close using several transparency layers.

Stronger visual conditions make the area closest to the rail more visible.

The gradient is cosmetic and contains no separate signal logic.

Rail Glow
The optional glow is scaled using ATR and Visual Strength.

Stronger conditions produce a slightly wider and more visible glow around the active rail.

This does not alter the actual rail level.

Trend Candles
Candles can be coloured according to the stored Aroon trend state:

  • Bullish = selected Bullish colour.
  • Bearish = selected Bearish colour.


The colour represents the indicator regime, not the direction of each individual candle.

Data Window
The indicator exposes:

  • Aroon Up: recency score for the highest high.
  • Aroon Down: recency score for the lowest low.
  • Aroon Bias: normalized difference between Up and Down.
  • Aroon Strength: absolute Aroon Bias expressed as a percentage.
  • Active Rail Width: current ATR- and Aroon-adjusted distance used for the raw rail.


Input Guide
Aroon Length
Controls the window used to locate the most recent highest high and lowest low.

Bias Threshold
Controls how much Aroon separation is required before establishing the opposite trend.

ATR Length
ATR period used to calculate rail width.

Base Width
Base ATR multiplier applied to the rail.

Strong Trend Width
Width multiplier used as Aroon Strength approaches its maximum.

Weak Trend Width
Width multiplier used when Aroon Up and Down are close together.

How to Use It
The indicator can be used as:

  • An Aroon-based bullish/bearish regime filter.
  • A trailing visual reference during an established trend.
  • A way to inspect the separation between Aroon Up and Aroon Down alongside an ATR-scaled rail.
  • A trend-change alert when the Aroon bias clears the opposite threshold.


Limitations
  • The indicator is reactive and uses current and historical price data.
  • Aroon measures the recency of highs and lows; it does not forecast future price direction.
  • The rail is derived from the current trend state and does not independently confirm or invalidate that state.
  • Higher Bias Threshold settings create more persistent regimes but can delay reversals.
  • Lower thresholds can produce more frequent changes in sideways conditions.
  • ATR and the Width settings materially affect the distance of the rail from price.


Alerts
The script includes:

  • Aroon Rail Bullish: trend state changes from bearish to bullish.
  • Aroon Rail Bearish: trend state changes from bullish to bearish.
  • Aroon Rail Flip: either transition occurs.


Summary
Aroon Trend Trail uses Aroon Up and Aroon Down to form a normalized directional bias.

A configurable threshold creates persistence around zero, so the existing trend remains active until the Aroon bias becomes strong enough in the opposite direction.

That trend state is then paired with an ATR-based trailing rail. The rail width changes with the absolute Aroon bias, and the active boundary ratchets upward during bullish regimes or downward during bearish regimes.

The result is a simple combination of an Aroon trend state and an adaptive trailing visual reference, with the two parts kept separate: Aroon determines the trend, while the ATR rail follows it.

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.