-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Indicator Name
Trend Tracer
Category
Trend
Description
🟠OVERVIEW
This tool builds a two-stage trend model that reacts to structure shifts while also showing how strong or weak the move is. It uses a mid-price band (from the highest high and lowest low over a lookback) and applies two Supertrend passes on top of it. The first pass smoothens the basis. The second pass refines that direction and produces the final trail used for signals. A gradient fill between the two trails uses RSI of price-to-trail distance to show when price is stretched or cooling off. The aim is to give traders a simple way to read trend alignment, pressure, and early turns without guessing.
🟠CONCEPTS
The script starts with a mid-range basis. This is the average of the rolling highest high and lowest low. It acts as a stable structure reference instead of raw close or typical price. From there, two Supertrend layers are applied:
• The first Supertrend uses a shorter ATR period and lower factor. It reacts faster and sets the main regime.
• The second Supertrend uses a slightly longer ATR and higher factor. It filters noise, waits for confirmed continuation, and generates the signal line.
The interaction between these trails matters. The outer Supertrend provides context by defining the broader regime. The inner Supertrend provides timing by flipping earlier and marking possible shifts. The gradient fill uses RSI of (close − supertrend value) to display when price stretches away from the trail. This shows strength, exhaustion, or compression within the trend.
🟠FEATURES
Bullish and bearish flip markers placed at recent highs/lows
snapshot
Rejection signals off the trend tracer line
snapshot
Alerts for bullish and bearish trend changes
snapshot
🟠USAGE
Setup: Add the script to your chart. Timeframe is flexible; lower timeframes show more flips while higher ones give cleaner swings. Adjust Length to change how wide the basis range is. Use the two ATR settings and factors to match the volatility of the market you trade.
Read the chart: When the refined trail (stv_) sits above price the regime is bearish; when below, it is bullish. The wide trail (stv) confirms the larger move. Watch the gradient fill: darker colors appear when price is stretched from the trail and lighter colors appear when the move is weakening. Flip markers ▲ or ▼ highlight the first clean shift of the refined trail.
Settings that matter: Increasing the Main Factor slows main-trend flips and filters chop. Increasing the Signal Factor delays the timing trail but reduces noise. Shortening Length makes the basis more reactive. ATR periods change how sensitive each Supertrend pass is to volatility.
Dec 6, 2025
Release Notes
Thumbnail
Dec 6, 2025
Release Notes
Thumbnail
Dec 6, 2025
Release Notes
Minor cleanups
Reference Chart(s)
Chart Description
See image
Parameters
period(int, default=14):source_column(str, default='Close'):
Source / Reference
//@Version=6
indicator("Trend Tracer [AlgoAlpha]", shorttitle="AlgoAlpha - Trend Tracer", overlay=true)
group_calcs = "Calculations"
group_app = "Appearance"
length = input.int(20, minval = 1, title="Length", group=group_calcs, tooltip="Main length for the indicator, a larger value results in longer term signals")
st1_factor = input.float(0.5, title="Main Factor", group=group_calcs, tooltip="Factor for the first Supertrend calculation step.")
st1_period = input.int(10, title="Main ATR Period", group=group_calcs, tooltip="ATR Period for the first Supertrend calculation step.")
st2_factor = input.float(0.7, title="Signal Factor", group=group_calcs, tooltip="Factor for the second Supertrend calculation step.")
st2_period = input.int(14, title="Signal ATR Period", group=group_calcs, tooltip="ATR Period for the second Supertrend calculation step.")
green = input.color(#00ffbb, title = "Bullish Colour", group = group_app, tooltip = "Color used for bullish visuals and positive sentiment texts.")
red = input.color(#ff1100, title = "Bearish Colour", group = group_app, tooltip = "Color used for bearish visuals and negative sentiment texts.")
lower = ta.lowest(length)
upper = ta.highest(length)
basis = math.avg(upper, lower)
calculateATR(source, atrLength) =>
highestHigh = ta.highest(source, atrLength)
lowestLow = ta.lowest(source, atrLength)
trueRange = na(highestHigh[1]) ? highestHigh - lowestLow : math.max(highestHigh - lowestLow, math.abs(highestHigh - source[1]), math.abs(lowestLow - source[1]))
ta.rma(trueRange, atrLength)
calculateSupertrend(factor, atrPeriod, source) =>
priceSource = source
atr = calculateATR(source, atrPeriod)
upperBand = priceSource + factor * atr
lowerBand = priceSource - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or source[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or source[1] > prevUpperBand ? upperBand : prevUpperBand
int trendDirection = na
float supertrendValue = na
prevSupertrend = supertrendValue[1]
if na(atr[1])
trendDirection := 1
else if prevSupertrend == prevUpperBand
trendDirection := source > upperBand ? -1 : 1
else
trendDirection := source < lowerBand ? 1 : -1
supertrendValue := trendDirection == -1 ? lowerBand : upperBand
[supertrendValue, trendDirection]
[stv, dir] = calculateSupertrend(st1_factor, st1_period, basis)
[stv_, dir_] = calculateSupertrend(st2_factor, st2_period, stv)
p1 = plot(stv_, color = color.new(dir_ > 0 ? red : green, 50))
p2 = plot(stv, color = color.new(dir_ > 0 ? red : green, 50), linewidth = 3)
dist = ta.rsi(close-stv, 14)
col = dir_ > 0 ? red : green
fill(p1, p2, color.from_gradient(dist, 0, 100, chart.bg_color, color.new(col, 50)))
lwst = ta.lowest(14)
hst = ta.highest(14)
bullish_cond = ta.crossunder(dir_, 0)
bearish_cond = ta.crossover(dir_, 0)
plotshape(bullish_cond ? lwst : na, "Bullish Signal", shape.labelup, location.absolute, green, size = size.small, text = "▲", textcolor = chart.fg_color)
plotshape(bearish_cond ? hst : na, "Bearish Signal", shape.labeldown, location.absolute, red, size = size.small, text = "▼", textcolor = chart.fg_color)
plotchar(dir_ < 0 and close > stv and open < stv ? lwst : na, "Bullish Bounce", "▲", location.absolute, green, size = size.tiny)
plotchar(dir_ > 0 and close < stv and open > stv ? hst : na, "Bearish Bounce", "▼", location.absolute, red, size = size.tiny)
//ALERTS
alertcondition(bullish_cond, title="Bullish Trend Change", message="Trend changed to Bullish")
alertcondition(bearish_cond, title="Bearish Trend Change", message="Trend changed to Bearish")
Expected Output Columns
No response
Deliverables Checklist
- Implementation in
pyindicators/indicators/(pandas + polars support) - Exports in
__init__.pyand__all__ - Unit tests in
tests/indicators/(pandas, polars, edge cases) - Documentation page in
docs/content/indicators/with chart image - Sidebar registration in
docs/sidebars.js - Entry in README.md features list
- Analysis notebook in
analysis/indicators/with plotly chart
Additional Context
No response