OPEN-SOURCE SCRIPT

EMA 9 vs 21 Spread Variance

28
EMA 9 vs 21 Spread Variance
What it does
Tracks the distance between EMA 9 and EMA 21, then measures how volatile that distance has been over your chosen lookback. The indicator plots the EMA spread around zero and a rolling variance of that spread. Rising variance signals expanding dispersion between the fast and slow EMAs, which often precedes momentum bursts or regime shifts. Falling variance points to compression and mean-reversion conditions.
How it is calculated
Fast EMA and slow EMA are computed on the selected source.
Spread = EMA9 minus EMA21, plotted around zero.
Variance = rolling variance of the spread over Variance Lookback. Variance is always non-negative.
For readability you can show the variance either on its raw scale, or fitted to the spread’s recent range so both lines are comparable in one pane.
How to read it
Spread near zero with variance rising suggests an impending expansion from balance.
Large positive spread with elevated variance confirms a strong up-trend that is still dynamic.
Large negative spread with elevated variance confirms a strong down-trend that is still dynamic.
Variance rolling over after a run warns that momentum dispersion is cooling and that a consolidation or pullback is likely.
The horizontal zero line applies to the spread only. Variance does not cross zero.
Inputs
Source: price series for EMAs.
Fast EMA Length and Slow EMA Length: defaults 9 and 21.
Variance Lookback: window for the spread variance, common ranges 20 to 100 on intraday charts and 50 to 200 on higher timeframes.
Show spread line and Fit variance to spread scale: display controls.
Suggested use
Combine with your breakout logic. Look for variance expansion from low levels as a filter before taking continuation entries.
Use as a volatility context for EMA cross systems. Crosses that occur with rising variance tend to travel farther than crosses that occur during compression.
Caveats
Variance reacts to spikes in the spread, so it can jump around news bars. Smoothing reduces noise but adds lag. Consider pairing with ATR or session filters if you only want signals during liquid hours.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.