Moving averages (EMA, SMA): types, settings and crossover alerts
Moving averages in SuperCharting: EMA, SMA, WMA, Hull and more, the MA crossover and ribbon built-ins, an EMA cross alert script and crossover strategies.
A moving average smooths price by averaging the last N bars, so the trend is easier to see through the noise. SuperCharting's library has the simple moving average (SMA), the exponential moving average (EMA) and more than ten other kinds, plus ready-made crossover and ribbon indicators. Add any of them from Indicators by typing "sma", "ema" or "moving average". This page explains how they differ, how to set them up, and how to get an alert when two averages cross.
The moving averages in the library
| Built-in | Default length | How it weights the bars |
|---|---|---|
| Simple moving average (SMA) | 9 | Every bar counts equally |
| Exponential moving average (EMA) | 9 | Recent bars count more, older bars fade gradually |
| Weighted moving average (WMA) | 9 | Weights fall in a straight line from newest to oldest |
| Smoothed moving average | 7 | Wilder's smoothing (RMA), slower than an EMA of the same length |
| Hull moving average (HMA) | 9 | Built from WMAs to reduce lag |
| Double / Triple exponential moving average (DEMA, TEMA) | 9 | EMAs of EMAs, combined to react faster |
| Volume-weighted moving average (VWMA) | 20 | Bars with more volume count more |
| Arnaud Legoux, Least squares, McGinley dynamic, Kaufman's adaptive | varies | Other ways of balancing smoothness and lag |
There are also combined tools:
- Moving average crossover: two SMAs (Short MA Length 9, Long MA Length 21), with a cross marker wherever they meet.
- Moving average ribbon: four averages, 20, 50, 100 and 200 by default. Each one can be SMA, EMA, SMMA (RMA), WMA or VWMA and has its own source and colour.
- Williams alligator: three displaced smoothed averages.
The lag trade-off applies to all of them. A shorter or more responsive average turns sooner but gives more false turns. A longer or smoother one gives fewer, later signals.
How to add an EMA or SMA in SuperCharting
- Open a chart, for example NSE:NIFTY on the 1D interval.
- Click Indicators, type "ema" and click Exponential moving average.
- Hover the legend line and click the gear for Settings.
- On Inputs, set Length (for example 50), Source (Close by default) and Offset.
- The SMA and EMA scripts also have a second smoothing line. Set its Type (None, SMA, SMA + Bollinger Bands, EMA, SMMA (RMA), WMA or VWMA) and its Length to draw an average of the average.
- On Style, set the colour and line thickness so each length is easy to tell apart.
- Repeat for a second length, such as a 200 SMA, and click Ok.
To get the same set of averages on every chart, save them once as an indicator template. The Technicals tab of the templates dialog already has Displaced EMA (Volume plus a 20 EMA shifted 5 bars), MA Exp Ribbon (eight EMAs from 20 to 55) and Bill Williams' 3 Lines.
How traders use moving averages
- Trend filter: price above a rising 200-day average is a common definition of a long-term uptrend. Some traders only take long setups on NSE stocks while that holds.
- Dynamic support and resistance: in a trend, pullbacks often pause near the 20 or 50 EMA. Traders watch how price behaves there rather than treating the line as an exact level.
- Crossovers: a faster average crossing above a slower one, such as 50 over 200 (often called a golden cross) or 20 over 50 for swing trades, marks a change in trend. Crosses come late by design.
- Slope: a flat average means a range. Many traders stop using crossover signals while the averages are flat and tangled.
These describe common practice. They are not recommendations. MACD measures the gap between two EMAs directly, and Supertrend is another way to follow a trend.
An EMA cross alert script
The built-in averages define no alerts, and a price alert compares price with a fixed number, not with a moving line. To be told when two averages cross, save this script in the Script Editor and add it from My scripts:
//@version=6
indicator("EMA 20 / 50 cross", "EMA cross", overlay = true)
fastLen = input.int(20, "Fast EMA", minval = 1)
slowLen = input.int(50, "Slow EMA", minval = 1)
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
plot(fast, "Fast EMA", color.blue)
plot(slow, "Slow EMA", color.orange, 2)
golden = ta.crossover(fast, slow)
death = ta.crossunder(fast, slow)
plotshape(golden, "Fast above slow", shape.triangleup, location.belowbar, color.green)
plotshape(death, "Fast below slow", shape.triangledown, location.abovebar, color.red)
alertcondition(golden, "Fast EMA crossed above slow", "Fast EMA crossed above slow EMA")
alertcondition(death, "Fast EMA crossed below slow", "Fast EMA crossed below slow EMA")
Steps for the alert
- Add the script to a chart such as XAUUSD 4h.
- In the legend's More menu choose Add alert on EMA cross….
- Pick "Fast EMA crossed above slow" as the condition.
- Set Trigger to Once per bar close, so a cross that reverses inside the bar is not reported.
- Choose an Expiration and your notifications, then click Create.
An alert uses the script's default inputs, so change 20 and 50 in the code if you want other lengths. Changing them in the Settings dialog only changes what you see on the chart. The price alerts guide covers triggers and expiry.
Testing a crossover strategy
The Strategies chip includes Two moving averages crossover. It goes long when a 9-bar SMA crosses above an 18-bar SMA and short on the opposite cross, and its two lengths can be changed in Settings. Add it to a chart, open the Strategy Tester from the legend's More menu, and set Commission and Slippage on the Properties tab before you read the results. To build your own version step by step, follow write your first strategy. Past results do not guarantee future results.
Frequently asked questions
Is the EMA better than the SMA?
Neither is better in general. The EMA turns sooner, the SMA is steadier. Pick one per purpose and keep it the same, so your readings stay comparable.
Why does my 200-day average look different on another platform?
Averages need history to settle. Different amounts of loaded history, different session times or a different source, such as close versus hlc3, change the early values. A chart can load up to 40,000 bars.
Can I put a moving average on RSI or volume?
Yes. Open the average's Settings and set Source to another indicator's plot; see indicators on indicators.
What does Offset do?
It shifts the line forwards (positive) or backwards (negative) by that many bars without changing its values. Displaced averages such as the Bill Williams' 3 Lines template use it.