WaveTrend Oscillator (WAVETREND)
Summary
WaveTrend Oscillator: how far the typical price sits from its own exponential average, divided by an exponential average of that distance and by Lambert's CCI constant, then smoothed. The reading is the plain stochastic's complaint answered a different way — rather than bounding the oscillator by construction, it scales it by how far price has recently been travelling, so the same numeric level means the same thing in a quiet market and a fast one. The oscillator line and its short simple average cross; the crossings that matter are the ones beyond the extremes, which the author draws at ±53 and ±60.
Chart
Chart metadata i
Outputs
outWT1:line·zero·positive·negative·levels: -60, -53, 53, 60outWT2:dash_line·zero·positive·negative
Formula
ap = (high + low + close) / 3
esa = EMA(ap, channelPeriod)
d = EMA(|ap - esa|, channelPeriod)
ci = (ap - esa) / (0.015 * d)
WT1 = EMA(ci, averagePeriod)
WT2 = SMA(WT1, signalPeriod)
Notes
- The middle stage is an exponential CCI, not
TA_CCI: CCI averages with a simple moving average and takes the mean deviation around that window's own average, where this uses two exponential averages. - On a market that has stopped moving, the exponential average stops moving too — once its step falls under half an ulp it freezes, a few ulps away from the price. That frozen gap is a real non-zero distance, so dividing by its own average walks the oscillator to ±66.67, an extreme reading produced by nothing but rounding. This answers 0 instead, by taking the distance as zero whenever the price and its average both repeat. Implementations without that test drift to the extreme on flat data, at a bar that depends on their arithmetic.
- A zero divisor is tested on the scaled deviation, the quantity the division actually uses, and answers the neutral 0 rather than dividing.
- Each exponential average is seeded with a simple average of its own first inputs, the same seeding TA-Lib's EMA uses, and each seeds on what the stage before it publishes.
TA_SetUnstablePeriod(TA_FUNC_UNST_EMA, ...)discards more of that warm-up, and it counts three times because there are three exponential stages. - The difference the author also plots is
TA_SUB(outWT1, outWT2).
Inputs
inHigh— High price seriesinLow— Low price seriesinClose— Close price series
Outputs
outWT1— WaveTrend oscillator lineoutWT2— Simple average of the oscillator line
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInChannelPeriod | integer | 10 | 2–100000 | Period of the price channel, used by both the average and the deviation |
optInAveragePeriod | integer | 21 | 1–100000 | Smoothing for the oscillator line |
optInSignalPeriod | integer | 4 | 1–100000 | Period of the simple average making the signal line |
Properties
Numerical Stability: Initial Unstable Period — Inherited from EMA, which WAVETREND computes internally; tunable via EMA's unstable period.
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
| ☐ Input Must Be Positive |
Example
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double high[252]; /* your data, oldest first */
double low[252]; /* your data, oldest first */
double close[252]; /* your data, oldest first */
double wt1[252], wt2[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_WAVETREND( 0, n - 1, high, low, close, 10, 21, 4, &outBegIdx, &outNBElement, wt1, wt2 );
printf( "%d values from bar %d:\n", outNBElement, outBegIdx );
printf( "wt1 = [%.4f, ..., %.4f]\n", wt1[0], wt1[outNBElement - 1] );
printf( "wt2 = [%.4f, ..., %.4f]\n", wt2[0], wt2[outNBElement - 1] );use ta_lib::Core;
let high = vec![0.0; 252]; // your data, oldest first
let low = vec![0.0; 252]; // your data, oldest first
let close = vec![0.0; 252]; // your data, oldest first
let mut wt1 = vec![0.0; 252];
let mut wt2 = vec![0.0; 252];
let core = Core::new();
let range = core.wavetrend(0, high.len() - 1, &high, &low, &close, 10, 21, 4,
&mut wt1, &mut wt2)?;
println!("{} values from bar {}:", range.count, range.beg_idx);
println!("wt1 = [{:.4}, ..., {:.4}]", wt1[0], wt1[range.count - 1]);
println!("wt2 = [{:.4}, ..., {:.4}]", wt2[0], wt2[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
import java.util.Locale;
double[] high = new double[252]; // your data, oldest first
double[] low = new double[252]; // your data, oldest first
double[] close = new double[252]; // your data, oldest first
double[] wt1 = new double[252];
double[] wt2 = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.wavetrend(0, high.length - 1, high, low, close, 10, 21, 4, wt1, wt2);
System.out.printf(Locale.ROOT, "%d values from bar %d:%n", r.count(), r.begIdx());
System.out.printf(Locale.ROOT, "wt1 = [%.4f, ..., %.4f]%n", wt1[0], wt1[r.count() - 1]);
System.out.printf(Locale.ROOT, "wt2 = [%.4f, ..., %.4f]%n", wt2[0], wt2[r.count() - 1]);using System;
using TALib;
var high = new double[252]; // your data, oldest first
var low = new double[252]; // your data, oldest first
var close = new double[252]; // your data, oldest first
var wt1 = new double[252];
var wt2 = new double[252];
var core = Core.Default;
OutRange r = core.Wavetrend(0, high.Length - 1, high, low, close, 10, 21, 4, wt1, wt2);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}:");
Console.WriteLine(FormattableString.Invariant($"wt1 = [{wt1[0]:F4}, ..., {wt1[r.Count - 1]:F4}]"));
Console.WriteLine(FormattableString.Invariant($"wt2 = [{wt2[0]:F4}, ..., {wt2[r.Count - 1]:F4}]"));import { wavetrend } from 'ta-lib';
const high = new Float64Array(252); // your data, oldest first
const low = new Float64Array(252); // your data, oldest first
const close = new Float64Array(252); // your data, oldest first
const { begIdx, outWt1, outWt2 } = wavetrend({ high, low, close }, {
channelPeriod: 10,
averagePeriod: 21,
signalPeriod: 4,
});
console.log(outWt1.length + ' values from bar ' + begIdx + ':');
console.log('outWt1 = [' + outWt1[0].toFixed(4) + ', ..., ' + outWt1[outWt1.length - 1].toFixed(4) + ']');
console.log('outWt2 = [' + outWt2[0].toFixed(4) + ', ..., ' + outWt2[outWt2.length - 1].toFixed(4) + ']');import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
high := make([]float64, 252) // your data, oldest first
low := make([]float64, 252) // your data, oldest first
close := make([]float64, 252) // your data, oldest first
wt1 := make([]float64, 252)
wt2 := make([]float64, 252)
core := talib.NewCore()
r, err := core.WAVETREND(0, len(high)-1, high, low, close, 10, 21, 4, wt1, wt2)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d:\n", r.NBElement, r.BegIdx)
fmt.Printf("wt1 = [%.4f, ..., %.4f]\n", wt1[0], wt1[r.NBElement-1])
fmt.Printf("wt2 = [%.4f, ..., %.4f]\n", wt2[0], wt2[r.NBElement-1])Implementation
Added in 0.8.3 (ta-lib-python 0.8.3).
TA-Lib Definition: wavetrend.c · wavetrend.yaml
| Native | File |
|---|---|
| C | ta_WAVETREND.c |
| Rust | wavetrend.rs |
| Java | Core_WAVETREND.java |
| C# | Core_WAVETREND.cs |
| TypeScript | wavetrend.ts |
| Go | wavetrend.go |
Python: talib.WAVETREND (ta-lib-python 0.8.3 or later), see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
wavetrend, wavetrend oscillator, WT
See Also
References
- LazyBear, "WaveTrend Oscillator [WT]", TradingView published script, 2014