Calculates the WaveTrend oscillator using channel and average exponential moving averages alongside a simple moving average signal line in a separate pane.
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
91 lines of Pine Script v6 from scripts/wavetrend-audit.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.
wavetrend-audit.pine
// Licence: Mozilla Public License 2.0
// Taught to Trade - WaveTrend Audit
// Written from scratch. The WaveTrend method is LazyBear's (WaveTrend Oscillator, 2014); credit to him.
// No code reused. Educational tool: it marks crosses on CLOSED bars only and counts, on the loaded history,
// how often the oscillator sits beyond each level and how often the lines cross.
//@version=6
indicator("Taught to Trade - WaveTrend Audit", shorttitle="TT WaveTrend Audit", overlay=false, max_labels_count=500)
// ---- Inputs
n1 = input.int(10, "Channel length (EMA)", minval=1)
n2 = input.int(21, "Average length (EMA)", minval=1)
sigLen = input.int(4, "Signal length (SMA)", minval=1)
lvl1 = input.float(60.0, "Outer level (+/-)", minval=0.0, step=0.5)
lvl2 = input.float(53.0, "Inner level (+/-)", minval=0.0, step=0.5)
confirm = input.bool(true, "Mark crosses only on closed bars")
showTbl = input.bool(true, "Show audit panel")
tblPos = input.string("Top right", "Panel position", options=["Top right", "Top left", "Bottom left", "Bottom right"])
// ---- WaveTrend maths (top level)
ap = hlc3
esa = ta.ema(ap, n1)
dev = ta.ema(math.abs(ap - esa), n1)
ci = dev == 0 ? 0.0 : (ap - esa) / (0.015 * dev)
wt1 = ta.ema(ci, n2)
wt2 = ta.sma(wt1, sigLen)
xUp = ta.crossover(wt1, wt2)
xDn = ta.crossunder(wt1, wt2)
okBar = confirm ? barstate.isconfirmed : true
upC = xUp and okBar
dnC = xDn and okBar
pend = confirm and not barstate.isconfirmed and (xUp or xDn)
// ---- Plots
hline(lvl1, "Outer +", color=color.new(color.red, 40))
hline(lvl2, "Inner +", color=color.new(color.red, 70), linestyle=hline.style_dotted)
hline(0, "Zero", color=color.new(color.gray, 60))
hline(-lvl2, "Inner -", color=color.new(color.teal, 70), linestyle=hline.style_dotted)
hline(-lvl1, "Outer -", color=color.new(color.teal, 40))
plot(wt1 - wt2, "WT1 - WT2", color=color.new(color.gray, 70), style=plot.style_area)
plot(wt1, "WT1", color=color.new(color.teal, 0), linewidth=2)
plot(wt2, "WT2 (signal)", color=color.new(color.orange, 0), linewidth=1)
plotshape(upC ? wt2 : na, "Cross up (closed bar)", shape.circle, location.absolute, color.new(color.teal, 0), size=size.tiny)
plotshape(dnC ? wt2 : na, "Cross down (closed bar)", shape.circle, location.absolute, color.new(color.orange, 0), size=size.tiny)
plotshape(pend ? wt2 : na, "Cross pending (open bar)", shape.circle, location.absolute, color.new(color.gray, 0), size=size.tiny)
// ---- Audit counters (closed bars only, so the open bar never double counts)
var int nBars = 0
var int nAbove1 = 0
var int nBelow1 = 0
var int nBeyond2 = 0
var int nCross = 0
var int nCrossOut = 0
var int lastX = na
var array<int> gaps = array.new<int>()
valid = not na(wt2)
if barstate.isconfirmed and valid
nBars += 1
nAbove1 += wt1 > lvl1 ? 1 : 0
nBelow1 += wt1 < -lvl1 ? 1 : 0
nBeyond2 += math.abs(wt1) > lvl2 ? 1 : 0
if xUp or xDn
nCross += 1
nCrossOut += math.abs(wt2) > lvl1 ? 1 : 0
if not na(lastX)
gaps.push(bar_index - lastX)
lastX := bar_index
pct(a, b) => b > 0 ? str.tostring(100.0 * a / b, "#.0") + "%" : "-"
pos = tblPos == "Top left" ? position.top_left : tblPos == "Bottom left" ? position.bottom_left : tblPos == "Bottom right" ? position.bottom_right : position.top_right
var table t = table.new(pos, 2, 7, bgcolor=color.new(color.black, 20), border_width=1)
if showTbl and barstate.islast
medGap = gaps.size() > 0 ? str.tostring(gaps.median(), "#.#") : "-"
table.cell(t, 0, 0, "WaveTrend Audit", text_color=color.white, text_size=size.small)
table.cell(t, 1, 0, str.tostring(nBars) + " closed bars", text_color=color.white, text_size=size.small)
table.cell(t, 0, 1, "Above +" + str.tostring(lvl1), text_color=color.white, text_size=size.small)
table.cell(t, 1, 1, pct(nAbove1, nBars), text_color=color.white, text_size=size.small)
table.cell(t, 0, 2, "Below -" + str.tostring(lvl1), text_color=color.white, text_size=size.small)
table.cell(t, 1, 2, pct(nBelow1, nBars), text_color=color.white, text_size=size.small)
table.cell(t, 0, 3, "Beyond +/-" + str.tostring(lvl2), text_color=color.white, text_size=size.small)
table.cell(t, 1, 3, pct(nBeyond2, nBars), text_color=color.white, text_size=size.small)
table.cell(t, 0, 4, "Crosses", text_color=color.white, text_size=size.small)
table.cell(t, 1, 4, str.tostring(nCross), text_color=color.white, text_size=size.small)
table.cell(t, 0, 5, "Median bars between", text_color=color.white, text_size=size.small)
table.cell(t, 1, 5, medGap, text_color=color.white, text_size=size.small)
table.cell(t, 0, 6, "Crosses beyond +/-" + str.tostring(lvl1), text_color=color.white, text_size=size.small)
table.cell(t, 1, 6, pct(nCrossOut, nCross), text_color=color.white, text_size=size.small)
// ---- Alerts only (no pushed signals)
alertcondition(upC, "WT1 crossed above WT2 (closed bar)", "WaveTrend: WT1 crossed above WT2 on a closed bar")
alertcondition(dnC, "WT1 crossed below WT2 (closed bar)", "WaveTrend: WT1 crossed below WT2 on a closed bar")
Overview
Taught to Trade - WaveTrend Audit plots the dual oscillator lines, their difference area, and configurable overbought and oversold thresholds. Bullish and bearish crossovers are highlighted, with an option to restrict marks to confirmed bar closes. An on-screen audit table displays historical statistics, including how frequently the oscillator breached threshold levels, total crossover counts, and median bar intervals between crosses.
WaveTrend oscillator with signal line and difference histogram
Closed-bar confirmation toggle for crossover signals
Audit table displaying level breach counts and cross statistics
Configurable inner and outer overbought and oversold thresholds
Median gap tracking between successive line crosses
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Channel length (EMA)
int
10
n1
Average length (EMA)
int
21
n2
Signal length (SMA)
int
4
sigLen
Outer level (+/-)
float
60.0
lvl1
Inner level (+/-)
float
53.0
lvl2
Mark crosses only on closed bars
bool
true
confirm
Show audit panel
bool
true
showTbl
Panel position
string
Top right
tblPos
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 scans a pasted list of symbols for RSI directional momentum and shows matching long and short signals in a table in a separate pane. The user chooses continuous break, continuous retracement, flip break, flip retracement, divergence, or hidden d
This indicator plots the RSI oscillator on the main chart and displays its value distribution in a table positioned at the top right. The script calculates the relative strength index using the input source and length, then plots horizontal lines at 0, 50, and
Market Speedometer plots a 0-100 market speed reading in a separate pane. It measures movement by bar-to-bar change, true range, or a short average of recent bars, then ranks that movement against ATR and a percentile lookback. An EMA smooths the reading, and
KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev
Calculates normalized reversal metrics across up to ten Forex currency pairs using user-selected moving average methods, including HarmonicMA, EMA, SMA, or WMA. The indicator identifies overbought, oversold, and mean-crossing conditions using a configurable th
The 8-Factor Composite Screener evaluates equities across fundamental and technical criteria, including valuation ratios, earnings and revenue growth, 12-month return momentum, proximity to 52-week highs, Stage 2 moving average alignment, benchmark relative st