Multiple Moving Averages

This script adds up to 5 moving averages to your chart – and you can select which moving average type (and timeframe) you want to use for each.

The possible MA type options are:

  • EMA
  • SMA
  • HMA
  • WMA
  • DEMA
  • VWMA
  • VWAP

ou can specify the length of each moving average, and you can override the type of all moving averages with the setting “ALL MA TYPE”.

There is also higher-timeframe functionality, so you can select the timeframe for each moving average.

If the “Smooth HTF MA” setting is turned on then the script will fill any gaps in intraday price data by averaging the difference (giving it a regular smooth look), and if it’s turned off then the HTF MAs will have a “stepped” look to them. Technically speaking, the non-smoothed setting is more accurate and so it’s turned off by default.

And finally, the first option “Color MA 1” will change your first MA’s color based on whether price action is above that MA’s price or below it. If it’s above it then the color turns green, if it’s below it then it turns red.

If you set an MA’s length to zero it will disable that MA.

There is also alert functionality.

Enjoy! Good luck with your trading :) 😎


This script also comes with alert functionality. You can be notified whenever price action touches any of the moving averages you draw to your chart:

  • MMA Alert = Price touched one of the moving averages
  • MA1 Alert = Price touched first MA
  • MA2 Alert = Price touched second MA
  • MA3 Alert = Price touched third MA
  • MA4 Alert = Price touched fourth MA
  • MA5 Alert = Price touched fifth MA


Multiple Moving Averages Indicator

Color MA1:
If enabled, the first MA on your chart will change color based on whether price action is trading above or below it (green for above, red for below).

MA Length #X:
This is the moving average length/period. If set to zero it will disable that moving average (except for MA#1 which must be a positive number).

MA Type #X:
This sets the type or style of your moving average. The possible options are EMA, SMA, HMA, WMA, DEMA, VWMA and VWAP.

This setting overrides all of your moving average types to be the same.

Smooth HTF MA?
If you are using a higher timeframe for any of your moving averages then this setting will affect how that moving average is drawn to your chart. On lower timeframes there are “gaps” in data for higher timeframe data, smoothing these gaps averages out the missing data which will result in a more “normal” looking MA – but the moving average price will not be technically accurate unlike the stepped version.

MA Timeframe #X:
This setting adjusts the timeframe source for each specific moving average (disabled/set to current timeframe by default).

Pine Script Basics Course Pine Script Mastery Course

Source Code

The source code for this particular script is private.

If you’d like to purchase access to all of my source code including detailed video lessons explaining how and why it was written, then you can find more information over at

And if not that’s fine! No hard feelings. Not everyone is willing to invest in their education and I respect that decision. But feel free to help yourself to my wealth of other open-source scripts.

Last Updated: 16th January, 2021

Free Premium Charts!

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments