8 Moving Averages TradingView script

I have made a basic Pine script for TradingView that allows you to use 8 different moving averages and modify them to your liking. You can choose from EMA, SMA, RMA, WMA and HMA. You can toggle them on and off, change colors and width.

Just copy the code down below, press the small up arrow in the lower right corner and then pick “Pine Editor“.

Then just press Open -> New blank indicator -> then paste the code -> Press Save -> Press “Add to chart

(You can also press the star next to the name to add it to your favorites)

Code to copy and paste:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mikul_
//@version=4 

// Inspired by a script made by BigBitsIO. 
// Find BigBitsIO at: https://www.tradingview.com/u/BigBitsIO/#published-scripts

study(shorttitle = "8 MA", title="Eight Moving Averages", overlay=true) 

// MA#Period is a variable used to store the indicator lookback period.  In this case, from the input.
// input - https://www.tradingview.com/pine-script-docs/en/v4/annotations/Script_inputs.html
MA1Period = input(10, title="MA1 Period")
MA1Type = input(title="MA1 Type", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA1Source = input(title="MA1 Source", type=input.source, defval=close)
MA2Period = input(50, title="MA2 Period")
MA2Type = input(title="MA2 Type", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA2Source = input(title="MA2 Source", type=input.source, defval=close)
MA3Period = input(200, title="MA3 Period")
MA3Type = input(title="MA3 Type", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA3Source = input(title="MA3 Source", type=input.source, defval=close)
MA4Period = input(7, title="MA4 Period")
MA4Type = input(title="MA4 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA4Source = input(title="MA4 Source", type=input.source, defval=close)
MA5Period = input(20, title="MA5 Period")
MA5Type = input(title="MA5 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA5Source = input(title="MA5 Source", type=input.source, defval=close)
MA6Period = input(50, title="MA6 Period")
MA6Type = input(title="MA6 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA6Source = input(title="MA6 Source", type=input.source, defval=close)
MA7Period = input(100, title="MA7 Period")
MA7Type = input(title="MA7 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA7Source = input(title="MA7 Source", type=input.source, defval=close)
MA8Period = input(200, title="MA8 Period")
MA8Type = input(title="MA8 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA8Source = input(title="MA8 Source", type=input.source, defval=close)

MA1 = if MA1Type == "SMA"
    sma(MA1Source, MA1Period)
else
    if MA1Type == "EMA"
        ema(MA1Source, MA1Period)
    else
        if MA1Type == "WMA"
            wma(MA1Source, MA1Period)
        else
            if MA1Type == "RMA"
                rma(MA1Source, MA1Period)
            else
                if MA1Type == "HMA"
                    wma(2*wma(MA1Source, MA1Period/2)-wma(MA1Source, MA1Period), round(sqrt(MA1Period)))
                    
MA2 = if MA2Type == "SMA"
    sma(MA2Source, MA2Period)
else
    if MA2Type == "EMA"
        ema(MA2Source, MA2Period)
    else
        if MA2Type == "WMA"
            wma(MA2Source, MA2Period)
        else
            if MA2Type == "RMA"
                rma(MA2Source, MA2Period)
            else
                if MA2Type == "HMA"
                    wma(2*wma(MA2Source, MA2Period/2)-wma(MA2Source, MA2Period), round(sqrt(MA2Period)))
                    
MA3 = if MA3Type == "SMA"
    sma(MA3Source, MA3Period)
else
    if MA3Type == "EMA"
        ema(MA3Source, MA3Period)
    else
        if MA3Type == "WMA"
            wma(MA3Source, MA3Period)
        else
            if MA3Type == "RMA"
                rma(MA3Source, MA3Period)
            else
                if MA3Type == "HMA"
                    wma(2*wma(MA3Source, MA3Period/2)-wma(MA3Source, MA3Period), round(sqrt(MA3Period)))
                    
MA4 = if MA4Type == "SMA"
    sma(MA4Source, MA4Period)
else
    if MA4Type == "EMA"
        ema(MA4Source, MA4Period)
    else
        if MA4Type == "WMA"
            wma(MA4Source, MA4Period)
        else
            if MA4Type == "RMA"
                rma(MA4Source, MA4Period)
            else
                if MA4Type == "HMA"
                    wma(2*wma(MA4Source, MA4Period/2)-wma(MA4Source, MA4Period), round(sqrt(MA4Period)))
                    
MA5 = if MA5Type == "SMA"
    sma(MA5Source, MA5Period)
else
    if MA5Type == "EMA"
        ema(MA5Source, MA5Period)
    else
        if MA5Type == "WMA"
            wma(MA5Source, MA5Period)
        else
            if MA5Type == "RMA"
                rma(MA5Source, MA5Period)
            else
                if MA5Type == "HMA"
                    wma(2*wma(MA5Source, MA5Period/2)-wma(MA5Source, MA5Period), round(sqrt(MA5Period)))
MA6 = if MA6Type == "SMA"
    sma(MA6Source, MA6Period)
else
    if MA6Type == "EMA"
        ema(MA6Source, MA6Period)
    else
        if MA6Type == "WMA"
            wma(MA6Source, MA6Period)
        else
            if MA6Type == "RMA"
                rma(MA6Source, MA6Period)
            else
                if MA6Type == "HMA"
                    wma(2*wma(MA6Source, MA6Period/2)-wma(MA6Source, MA6Period), round(sqrt(MA6Period)))
MA7 = if MA7Type == "SMA"
    sma(MA7Source, MA7Period)
else
    if MA7Type == "EMA"
        ema(MA7Source, MA7Period)
    else
        if MA7Type == "WMA"
            wma(MA7Source, MA7Period)
        else
            if MA7Type == "RMA"
                rma(MA7Source, MA7Period)
            else
                if MA7Type == "HMA"
                    wma(2*wma(MA7Source, MA7Period/2)-wma(MA7Source, MA7Period), round(sqrt(MA7Period)))
MA8 = if MA8Type == "SMA"
    sma(MA8Source, MA8Period)
else
    if MA8Type == "EMA"
        ema(MA8Source, MA8Period)
    else
        if MA7Type == "WMA"
            wma(MA8Source, MA8Period)
        else
            if MA8Type == "RMA"
                rma(MA8Source, MA8Period)
            else
                if MA8Type == "HMA"
                    wma(2*wma(MA8Source, MA8Period/2)-wma(MA8Source, MA8Period), round(sqrt(MA8Period)))
                    

plot(MA1, color=#fff000, linewidth=3)
plot(MA2, color=color.green, linewidth=3)
plot(MA3, color=color.white, linewidth=4)
plot(MA4, color=#e91e63, linewidth=2) 
plot(MA5, color=#da00ff, linewidth=3) 
plot(MA6, color=color.orange, linewidth=2) 
plot(MA7, color=color.blue, linewidth=2)
plot(MA8, color=#26a69a, linewidth=2)

Leave a Comment