SuperCharting
Sign in Get started Account Open charts

Learn / Indicators

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-inDefault lengthHow it weights the bars
Simple moving average (SMA)9Every bar counts equally
Exponential moving average (EMA)9Recent bars count more, older bars fade gradually
Weighted moving average (WMA)9Weights fall in a straight line from newest to oldest
Smoothed moving average7Wilder's smoothing (RMA), slower than an EMA of the same length
Hull moving average (HMA)9Built from WMAs to reduce lag
Double / Triple exponential moving average (DEMA, TEMA)9EMAs of EMAs, combined to react faster
Volume-weighted moving average (VWMA)20Bars with more volume count more
Arnaud Legoux, Least squares, McGinley dynamic, Kaufman's adaptivevariesOther ways of balancing smoothness and lag

There are also combined tools:

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

  1. Open a chart, for example NSE:NIFTY on the 1D interval.
  2. Click Indicators, type "ema" and click Exponential moving average.
  3. Hover the legend line and click the gear for Settings.
  4. On Inputs, set Length (for example 50), Source (Close by default) and Offset.
  5. 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.
  6. On Style, set the colour and line thickness so each length is easy to tell apart.
  7. 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

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

  1. Add the script to a chart such as XAUUSD 4h.
  2. In the legend's More menu choose Add alert on EMA cross….
  3. Pick "Fast EMA crossed above slow" as the condition.
  4. Set Trigger to Once per bar close, so a cross that reverses inside the bar is not reported.
  5. 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.

Try it on a live chart

SuperCharting runs in your browser: charts, Pine-compatible scripts, the Strategy Tester, alerts and the screener, with Indian and global markets.

Create a free account More guides