Trend Reversal Indicator — Free Pine Script v6 for TradingView
- trend-reversal-indicator.pine — the complete Pine Script v6 source
- README-FIRST.md — what it does and how to install it
- FREE-LICENSE.md — the free-edition license terms
About this product
Trend Reversal Indicator is a free Pine Script v6 indicator by Script Master Labs. It measures an EMA trend state and marks confirmed closes through the prior range against it, with relative-volume confirmation. The complete source is printed in full on this page and in the free download — paste it into TradingView's Pine Editor and it runs on TradingView's free plan. No payment, no account, no subscription.
What it computes, in its own terms: it a mechanical trend state from an EMA — up, down, or neutral — and marks reversal events: after a trend state has persisted for a minimum run of bars, a confirmed close through the prior range against that state, with relative-volume confirmation. A marked reversal records that the stated conditions occurred on that bar; it is not evidence of what price will do next, and the indicator makes no prediction and no profitability claim.
How to use it
Open TradingView's Pine Editor, create a new blank script, paste the source, save, and click Add to chart. Adjust the inputs from the gear icon. The full source is printed on this page below, and the free download carries the same source file with an install README and the free-edition license.
Free edition vs paid edition
The script file is the complete indicator — the same Pine Script v6 source sold in the paid edition (https://dual.scriptmasterlabs.com/product/trend-reversal-indicator, $29 one-time). The paid edition adds the full written user guide, the evidence receipt, and the licensing and security reviews. Nothing in the script is held back from the free edition.
More free tools — free Pine Script v6 indicators and strategies, free trading calculators and a free x402 pre-payment trust check — are collected on the Free Tools hub. Educational software, not financial advice: it measures and draws a stated rule; it does not predict price and shows no win rate.
The complete Pine Script v6 source — free, on this page
Trend Reversal Indicator is a free Pine Script v6 indicator by Script Master Labs. It measures an EMA trend state and marks confirmed closes through the prior range against it, with relative-volume confirmation. The complete source is printed in full on this page and in the free download — paste it into TradingView's Pine Editor and it runs on TradingView's free plan. No payment, no account, no subscription.
// © 2026 Script Master Labs LLC — Trend Reversal Indicator for TradingView
// Research-based, original SML engineering. This indicator MEASURES a
// mechanical trend state from an EMA and MARKS the bars where price closes
// through the prior range against that state with relative-volume
// confirmation. It makes no prediction and no profitability claim. A marked
// reversal event records that the stated conditions occurred on that bar;
// it is not evidence of what price will do next.
//@version=6
indicator("SML Trend Reversal Indicator", shorttitle = "SML Trend Reversal", overlay = true, max_labels_count = 500)
// ── Mechanical definition ───────────────────────────────────────────────────
// Trend state, from EMA(trendLen):
// DOWN — close < EMA and EMA is falling versus 5 bars ago.
// UP — close > EMA and EMA is rising versus 5 bars ago.
// NEUTRAL — anything else.
// The script counts consecutive bars spent in the current state.
// Reversal UP event — all of the following on one confirmed bar:
// (1) the prior state was DOWN for at least minTrendBars consecutive bars,
// (2) the bar CLOSES above the highest high of the prior breakLen bars
// (excluding the current bar),
// (3) RVOL = volume / SMA(volume, 20) is at least rvolMin.
// Reversal DOWN event is the mirror image (prior UP state, close below the
// lowest low of the prior breakLen bars, same RVOL condition).
// If the symbol has no volume data, the RVOL condition is treated as
// satisfied and the table shows RVOL as "n/a".
// Events are evaluated only on confirmed bars (barstate.isconfirmed), so a
// marker, once drawn on a closed bar, never moves or disappears.
// ── Inputs ──────────────────────────────────────────────────────────────────
grpTrend = "Trend"
trendLen = input.int(50, "Trend EMA length", minval = 2, maxval = 500, step = 1, group = grpTrend)
minTrendBars = input.int(10, "Minimum bars in prior trend state", minval = 1, maxval = 200, step = 1, group = grpTrend)
grpRev = "Reversal"
breakLen = input.int(20, "Breakout lookback (prior bars)", minval = 2, maxval = 200, step = 1, group = grpRev)
grpVol = "Volume confirmation"
rvolMin = input.float(1.5, "Minimum RVOL (volume / SMA(volume, 20))", minval = 0.0, maxval = 10.0, step = 0.1, group = grpVol)
grpDisp = "Display"
emaColor = input.color(color.new(color.blue, 0), "EMA line color", group = grpDisp)
emaWidth = input.int(2, "EMA line width", minval = 1, maxval = 4, step = 1, group = grpDisp)
upColor = input.color(color.new(color.lime, 0), "Reversal UP marker color", group = grpDisp)
downColor = input.color(color.new(color.red, 0), "Reversal DOWN marker color", group = grpDisp)
markerShape = input.string("Arrow", "Marker shape", options = ["Arrow", "Triangle"], group = grpDisp)
markerSize = input.string("Small", "Marker size", options = ["Tiny", "Small"], group = grpDisp)
labelMode = input.string("Buy/Sell", "Marker label mode", options = ["Buy/Sell", "Call/Put"], group = grpDisp)
grpTable = "Table"
showTable = input.bool(true, "Show table", group = grpTable)
tableSize = input.string("Small", "Table size", options = ["Tiny", "Small", "Normal"], group = grpTable)
tablePos = input.string("Top Right", "Table position", options = ["Top Right", "Top Left", "Bottom Right", "Bottom Left"], group = grpTable)
// ── Trend state ─────────────────────────────────────────────────────────────
ema = ta.ema(close, trendLen)
emaRising = not na(ema[5]) and ema > ema[5]
emaFalling = not na(ema[5]) and ema < ema[5]
rawState = close < ema and emaFalling ? -1 : close > ema and emaRising ? 1 : 0
// ── Volume ──────────────────────────────────────────────────────────────────
hasVol = not na(volume)
volSma = ta.sma(volume, 20)
rvol = hasVol and not na(volSma) and volSma > 0 ? volume / volSma : na
rvolOk = not hasVol or (not na(rvol) and rvol >= rvolMin)
// ── Breakout levels (prior bars only — current bar excluded) ────────────────
breakHigh = ta.highest(high, breakLen)[1]
breakLow = ta.lowest(low, breakLen)[1]
// ── Confirmed-bar state machine and events ──────────────────────────────────
var int curState = 0
var int barsInState = 0
var int prevState = 0
var int prevBars = 0
var string lastEvent = "None"
var bool revUp = false
var bool revDown = false
revUp := false
revDown := false
if barstate.isconfirmed
revUp := prevState == -1 and prevBars >= minTrendBars and not na(breakHigh) and close > breakHigh and rvolOk
revDown := prevState == 1 and prevBars >= minTrendBars and not na(breakLow) and close < breakLow and rvolOk
if revUp
lastEvent := "Reversal UP (bar " + str.tostring(bar_index) + ")"
if revDown
lastEvent := "Reversal DOWN (bar " + str.tostring(bar_index) + ")"
if rawState == curState
barsInState += 1
else
curState := rawState
barsInState := 1
prevState := curState
prevBars := barsInState
// ── Plots ───────────────────────────────────────────────────────────────────
plot(ema, "Trend EMA", color = emaColor, linewidth = emaWidth)
plot(rvol, "RVOL (data window)", display = display.data_window)
markerSz = markerSize == "Tiny" ? size.tiny : size.small
upShape = markerShape == "Arrow" ? shape.arrowup : shape.triangleup
downShape = markerShape == "Arrow" ? shape.arrowdown : shape.triangledown
upText = labelMode == "Buy/Sell" ? "BUY" : "CALL"
downText = labelMode == "Buy/Sell" ? "SELL" : "PUT"
plotshape(revUp, title = "Reversal UP", style = upShape, location = location.belowbar, color = upColor, textcolor = color.white, size = markerSz, text = upText)
plotshape(revDown, title = "Reversal DOWN", style = downShape, location = location.abovebar, color = downColor, textcolor = color.white, size = markerSz, text = downText)
// ── Alerts (descriptive only — a recorded event, not a signal to trade) ─────
alertcondition(revUp, title = "Reversal UP event", message = "Trend reversal UP event on {{exchange}}:{{ticker}} ({{interval}}): close crossed above the prior breakout high after a sustained DOWN state with RVOL confirmation.")
alertcondition(revDown, title = "Reversal DOWN event", message = "Trend reversal DOWN event on {{exchange}}:{{ticker}} ({{interval}}): close crossed below the prior breakout low after a sustained UP state with RVOL confirmation.")
// ── Smart table (all text white) ────────────────────────────────────────────
pos = switch tablePos
"Top Left" => position.top_left
"Bottom Right" => position.bottom_right
"Bottom Left" => position.bottom_left
=> position.top_right
txtSz = switch tableSize
"Tiny" => text.tiny
"Normal" => text.normal
=> text.small
var table tbl = table.new(pos, 2, 5, bgcolor = color.new(color.black, 20), border_width = 1, border_color = color.white)
stateTxt = curState == -1 ? "DOWN" : curState == 1 ? "UP" : "NEUTRAL"
rvolTxt = hasVol ? (na(rvol) ? "n/a" : str.tostring(rvol, "#.##")) : "n/a"
if barstate.islast and showTable
table.cell(tbl, 0, 0, "Trend state", text_color = color.white, text_size = txtSz)
table.cell(tbl, 1, 0, stateTxt, text_color = color.white, text_size = txtSz)
table.cell(tbl, 0, 1, "Bars in state", text_color = color.white, text_size = txtSz)
table.cell(tbl, 1, 1, str.tostring(barsInState), text_color = color.white, text_size = txtSz)
table.cell(tbl, 0, 2, "RVOL", text_color = color.white, text_size = txtSz)
table.cell(tbl, 1, 2, rvolTxt, text_color = color.white, text_size = txtSz)
table.cell(tbl, 0, 3, "EMA", text_color = color.white, text_size = txtSz)
table.cell(tbl, 1, 3, na(ema) ? "n/a" : str.tostring(ema, format.mintick), text_color = color.white, text_size = txtSz)
table.cell(tbl, 0, 4, "Last reversal", text_color = color.white, text_size = txtSz)
table.cell(tbl, 1, 4, lastEvent, text_color = color.white, text_size = txtSz)
if barstate.islast and not showTable
table.clear(tbl, 0, 0, 1, 4)
Questions about this product
Is there a free Pine Script for trend reversals on TradingView?
Yes. Script Master Labs publishes this Trend Reversal Indicator as a free Pine Script v6 download on SML Dual Market (https://dual.scriptmasterlabs.com/product/free-trend-reversal-indicator). The complete source is printed in full on the product page and in the free download — no payment, no account, no subscription.
How do I use the Trend Reversal Indicator?
Open TradingView's Pine Editor, create a new blank script, paste the source, click Save, then Add to chart. Adjust the inputs from the gear icon. TradingView's first-steps page shows where the editor opens: https://tradingview.com/pine-script-docs/primer/first-steps
Does it work on TradingView's free plan?
Yes. Paste the source into TradingView's Pine Editor and add it to your chart; the free plan runs custom indicators.
Is the free edition the complete script?
Yes — the same Pine Script v6 source file sold in the paid edition ($29 one-time). The paid edition adds the full written user guide, the evidence receipt, and the licensing and security reviews; nothing in the script itself is held back.
Does it repaint?
No. Its events are computed on confirmed bars only; a marker, once printed, does not move or disappear.