11 Essential Moving Averages for Trading
- Doji

- May 24, 2024
- 7 min read
Updated: Oct 20, 2024
How to Use and Read Almost any Type of Moving Average
Moving averages are fundamental tools in technical analysis, primarily used to identify trends. More than smoothing out price data, moving averages can be used to improve many indicators, such as oscillators and volume. In this article, we will explore 11 different types of moving averages, their unique characteristics, and how to use them effectively in trading.

1. Simple Moving Average (SMA)
Description: Calculates the average of a security's price over a specified number of periods.
Usage: Commonly used to smooth out price data and identify trends. A 50-day SMA crossing above the 200-day SMA (a.k.a. Golden Cross) indicates a bullish trend.
Code (ProRealTime)
lookbackPeriod = 50
sumPrice = 0
for i = 0 to lookbackPeriod - 1 do
sumPrice = sumPrice + close[i]
next
SMA = sumPrice / lookbackPeriod
return SMA as "SMA"
Note: ProRealTime has this indicator as standard, called "Average".
2. Exponential Moving Average (EMA)
Description: Gives more weight to recent prices, making it more responsive to new information.
Usage: Effective for capturing short-term trends. The 20-day EMA is often used to identify short-term momentum.
Code (ProRealTime)
lookbackPeriod = 20
alpha = 2 / (lookbackPeriod + 1)
if barindex = lookbackPeriod then
sumPrice = 0
for i = 0 to lookbackPeriod - 1
sumPrice = sumPrice + close[i]
next
EMA = sumPrice / lookbackPeriod
elsif barindex > lookbackPeriod then
EMA = alpha * close + (1 - alpha) * EMA[1]
endif
return EMA as "EMA"
Note: ProRealTime has this indicator as standard, called "ExponentialAverage".
3. Weighted Moving Average (WMA)
Description: Assigns more weight to recent prices by multiplying each price by a weight.
Usage: Useful for identifying trends with reduced lag compared to SMA. It is often used in combination with other indicators.
Code (ProRealTime)
lookbackPeriod = 20
weights = 0
weightedSum = 0
for i = 0 to lookbackPeriod - 1 do
weight = lookbackPeriod - i
weights = weights + weight
weightedSum = weightedSum + close[i] * weight
next
WMA = weightedSum / weights
return WMA as "WMA"
Note: ProRealTime has this indicator as standard, called "WeightedAverage".
4. Wilder’s Moving Average
Description: A variation of the EMA that smooths the price data using a different formula, developed by J. Welles Wilder.
Usage: Commonly used in Wilder’s other indicators like the RSI to reduce noise and smooth out price data.
Code (ProRealTime)
lookbackPeriod = 14
WildMA = 0
if barindex = lookbackPeriod then
for i = 0 to lookbackPeriod - 1 do
WildMA = WildMA + close[i]
next
WildMA = WildMA / lookbackPeriod
elsif barindex > lookbackPeriod then
WildMA = (WildMA[1] * (lookbackPeriod - 1) + close) / lookbackPeriod
endif
return WildMA as "WilderMA"
Note: ProRealTime has this indicator as standard, called "WilderAverage".
5. Triangular Moving Average (TMA)
Description: A double-smoothed SMA, which applies the SMA twice to the price data.
Usage: Provides a very smooth line that is effective in identifying long-term trends but with more lag.
Code (ProRealTime)
lookbackPeriod = 20
sumPrice = 0
sumSMA = 0
for i = 0 to lookbackPeriod - 1 do
sumPrice = sumPrice + close[i]
next
SMA = sumPrice / lookbackPeriod
for i = 0 to lookbackPeriod - 1 do
sumSMA = sumSMA + SMA[i]
next
TMA = sumSMA / lookbackPeriod
return TMA as "TMA"
Note: ProRealTime has this indicator as standard, called "TriangularAverage".
6. Time Series Moving Average
Description: Uses regression analysis to fit a line through the price points and project it forward.
Usage: Suitable for forecasting and reducing lag.
Code (ProRealTime)
lookbackPeriod = 20
sumX = 0
sumY = 0
sumXY = 0
sumXX = 0
for i = 0 to lookbackPeriod - 1 do
sumX = sumX + i
sumY = sumY + close[i]
sumXY = sumXY + i * close[i]
sumXX = sumXX + i * i
next
slope = (lookbackPeriod * sumXY - sumX * sumY) / (lookbackPeriod * sumXX - sumX * sumX)
intercept = (sumY - slope * sumX) / lookbackPeriod
TSMA = slope * (lookbackPeriod - 1) + intercept
return TSMA as "TSMA"
Note: ProRealTime has this indicator as standard, called "TimeSeriesAverage".
7. Hull Moving Average (HMA)
Description: Designed to reduce lag and improve smoothness by using weighted moving averages.
Usage: Effective in fast-moving markets where quick response to price changes is crucial. It’s often used in short-term trading strategies.
Code (ProRealTime)
lookbackPeriod = 20
weightsHalf = 0
weightedSumHalf = 0
for i = 0 to lookbackPeriod / 2 - 1
weight = lookbackPeriod / 2 - i
weightsHalf = weightsHalf + weight
weightedSumHalf = weightedSumHalf + close[i] * weight
next
wmaHalf = weightedSumHalf / weightsHalf
weightsFull = 0
weightedSumFull = 0
for i = 0 to lookbackPeriod - 1
weight = lookbackPeriod - i
weightsFull = weightsFull + weight
weightedSumFull = weightedSumFull + close[i] * weight
next
wmaFull = weightedSumFull / weightsFull
weightsSqrt = 0
weightedSumSqrt = 0
for i = 0 to sqrt(lookbackPeriod) - 1
weight = sqrt(lookbackPeriod) - i
weightsSqrt = weightsSqrt + weight
weightedSumSqrt = weightedSumSqrt + (2 * wmaHalf - wmaFull)[i] * weight
next
HMA = weightedSumSqrt / weightsSqrt
return HMA as "HMA"
Note: ProRealTime has this indicator as standard, called "HullAverage".
8. Zero-Lag Moving Average
Description: Combines a simple moving average and a correction factor to eliminate lag.
Usage: Useful in fast markets where lag is a significant concern, providing timely signals without delay typical of SMAs or EMAs.
Code (ProRealTime)
lookbackPeriod = 20
alpha = 2 / (lookbackPeriod + 1)
if barindex < lookbackPeriod then
sumPrice = 0
for i = 0 to barindex do
sumPrice = sumPrice + close[i]
next
EMA = sumPrice / (barindex + 1)
else
EMA = alpha * close + (1 - alpha) * EMA[1]
endif
if barindex >= lookbackPeriod then
ZLMA = 2 * EMA - EMA[lookbackPeriod]
else
ZLMA = EMA
endif
return ZLMA as "Zero-Lag MA"
Note: ProRealTime has this indicator as standard, called "ZLEMA".
9. Double Exponential Moving Average (DEMA)
Description: Uses two EMAs to reduce lag and improve responsiveness.
Usage: Effective for short-term trend following, as it provides quicker signals compared to a single EMA.
Code (ProRealTime)
lookbackPeriod = 20
alpha = 2 / (lookbackPeriod + 1)
EMA1 = close[0]
for i = 1 to lookbackPeriod - 1
EMA1 = EMA1 + alpha * (close[i] - EMA1)
next
EMA2 = EMA1
for i = 1 to lookbackPeriod - 1
EMA2 = EMA2 + alpha * (EMA1[i] - EMA2)
next
DoEMA = 2 * EMA1 - EMA2
return DoEMA as "DEMA"
Note: ProRealTime has this indicator as standard, called "DEMA".
10. Triple Exponential Moving Average (TEMA)
Description: Uses three EMAs to further reduce lag.
Usage: Ideal for capturing short-term trends with minimal lag, making it useful in high-frequency trading.
Code (ProRealTime)
lookbackPeriod = 20
alpha = 2 / (lookbackPeriod + 1)
EMA1 = close[0]
for i = 1 to lookbackPeriod - 1
EMA1 = EMA1 + alpha * (close[i] - EMA1)
next
EMA2 = EMA1
for i = 1 to lookbackPeriod - 1
EMA2 = EMA2 + alpha * (EMA1[i] - EMA2)
next
EMA3 = EMA2
for i = 1 to lookbackPeriod - 1
EMA3 = EMA3 + alpha * (EMA2[i] - EMA3)
next
TrEMA = 3 * EMA1 - 3 * EMA2 + EMA3
return TrEMA as "TEMA"
Note: ProRealTime has this indicator as standard, called "TEMA".
11. Adaptive Moving Average (AMA)
Description: Adjusts the smoothing constant based on the volatility and price trend.
Usage: Provides a balance between smoothness and responsiveness, suitable for dynamic trading environments.
Code (ProRealTime)
lookbackPeriod = 20
fastest = 2 / (2 + 1)
slowest = 2 / (30 + 1)
if barindex < lookbackPeriod then
AMA = close
else
volSum = 0
for i = 0 to lookbackPeriod - 1 do
volSum = volSum + abs(close[i] - close[i + 1])
next
efficiencyRatio = abs(close - close[lookbackPeriod]) / volSum
sc = efficiencyRatio * (fastest - slowest) + slowest
smoothingConstant = sc * sc
AMA = AMA[1] + smoothingConstant * (close - AMA[1])
endif
return AMA as "AMA"
Note: ProRealTime has this indicator as standard, called "AdaptiveAverage".
Comparison of Different Types of Moving Averages
It may be difficult to understand the difference just by reading, so let's put these moving averages on a chart and have a look. All of the below have a 20 candle lookback period.

As you can see, the difference between 20-period averages can be huge, depending on how you calculate. But they're all good to keep in your trading toolbox for different purposes. Try them out and discover which ones can improve your strategies.
FAQ
Q: Which moving average is best for day trading?
A: For day trading, the Exponential Moving Average (EMA) is often the go-to. It's super responsive to recent price changes, helping you catch those short-term moves. The shorter the period, like a 9 or 12 EMA, the better it is for quick trades.
Q: Which moving average is best for swing trading?
A: Swing traders usually prefer the Simple Moving Average (SMA). It smooths out the price data nicely and helps you focus on the overall trend without getting distracted by the noise. A 50 or 200-period SMA can be great for identifying those medium-term trends.
Q: Which moving average is best for scalping?
A: Scalping needs something fast and responsive, so the Hull Moving Average (HMA) is a great choice. It's designed to reduce lag and give you smoother signals. You’ll find it helpful for those ultra-short-term trades.
Q: Which moving average is best for generating signals?
A: The Triple Exponential Moving Average (TEMA) is awesome for generating signals. It combines multiple EMAs to give you faster and more accurate signals, which is perfect for making timely entry and exit decisions.
Q: Which moving average is best for defining trends?
A: The Time Series Moving Average is excellent for defining trends. It uses linear regression to create a best-fit line for your data, helping you clearly see the direction of the trend. Perfect for getting a good sense of where the market is headed.
Q: Which moving averages are best to combine?
A: Combining moving averages can give you a better picture. A popular combo is the 50-period SMA with the 200-period SMA for longer-term trends, and the 9-period EMA with the 21-period EMA for shorter-term signals. This way, you get the best of both worlds – smooth trends and responsive signals.


