Updated version of my Moving averages script (code updated!)

UPDATE: Code has now been updated so it will be a bit more clear in the settings menu. I also made the SMA’s thinner by default

UPDATE 2: Ichimoku signals have now been updated so that you can change the style and position on them.

UPDATE 3: From now on you can just add the indicator on the link below, and you will get every update automatically.

https://www.tradingview.com/script/oBSDFUhK-MA-BB-Ichi-Multi-Moving-averages-Bollinger-bands-Ichimoku/

I have now updated my moving averages script to include Bollinger bands and Ichimoku cloud as well. (so that you can have more indicators without wasting the amount of available indicators on Trading view ) You can add it the same way as described in the post for the old script. (Press here)

In the new script you can still toggle and change everything, but now you can also toggle ichimoku cloud and bollinger bands on and off, as well as “use all moving averages” or just the first 4 moving averages as a quick toggle.

Just copy and paste this code into your Pine editor on trading view, save and add to chart. (Instructions)

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

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

study(shorttitle = "MA/BB/Ichi", title="[MA/BB/Ichi] Multi Moving averages, Bollinger bands & Ichimoku", overlay=true) 

showema = input(true, title = "Show only first 3 EMA's & 20 SMA")
showma = input(false, title = "Show All MA's")
showbb = input(true, title = "Show Bollinger Bands")
showichi = input(true, title = "Show Ichimoku cloud")


// Ichimoku cloud --------------------------------------------------------------

conversionPeriods = input(9, minval=1, title="Conversion Line Length")
basePeriods = input(26, minval=1, title="Base Line Length")
laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Length")
displacement = input(26, minval=1, title="Displacement")
donchian(len) => avg(lowest(len), highest(len))

conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)

ichiup = crossover(conversionLine, baseLine)
ichidown= crossover(baseLine, conversionLine)
plotshape( ichiup ? conversionLine : na, "Ichi long", style=shape.circle, location = location.absolute, color=#00ff00, transp=0, size=size.small) // if you want to change size, you can switch out size.small to size.tiny or size.normal or size.large or size.huge
plotshape( ichidown ? conversionLine : na, "Ichi short", style=shape.circle, location = location.absolute, color=#ff1100, transp=0, size=size.small) // if you want to change size, you can switch out size.small to size.tiny or size.normal or size.large or size.huge

plot(showichi ? conversionLine : na, color=#009688, transp=25, title="Ichi Tenkan", linewidth=2) // 00e2ff
plot(showichi ? baseLine : na, color=#f44336, transp=25, title="Ichi Kijun", linewidth=2) // ff1100
plot(showichi ? close : na, offset = -displacement + 1, color=#00ff00, transp=25, title="Ichi Lagging Span") // #459915

p1 = plot(showichi ? leadLine1 : na, offset = displacement - 1, color=#4CAF50, transp=25, title="Ichi Lead 1")
p2 = plot(showichi ? leadLine2 : na, offset = displacement - 1, color=#FF5252, transp=25, title="Ichi Lead 2")

if showichi == true
    p1=false
    p2=false
fill(p1, p2, color = leadLine1 > leadLine2 ? #4CAF50 : #FF5252)



// Bollinger bands: ------------------------------------------------------------

length = input(20, minval=1)
src = input(close, title="Source")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
plot(showbb ? basis : na, "BB Basis", color=#da00ff, offset = offset, linewidth=2)
p11 = plot(showbb ? upper : na, "BB Upper", color=#e91e63, offset = offset)
p22 = plot(showbb ? lower : na, "BB Lower", color=#e91e63, offset = offset)
if showbb == true
    p11=false
    p22=false

fill(p11, p22, title = "BB Background", color=#00bcd4, transp=90) // nice colors #00bcd4 #da00ff



// Moving averages: ------------------------------------------------------------

MA1Period = input(10, title="MA 1 Period (EMA 10)")
MA1Type = input(title="MA 1 Type", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA1Source = input(title="MA 1 Source", type=input.source, defval=close)
MA2Period = input(50, title="MA 2 Period (EMA 50)")
MA2Type = input(title="MA 2 Type", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA2Source = input(title="MA 2 Source", type=input.source, defval=close)
MA3Period = input(200, title="MA 3 Period (EMA 200)")
MA3Type = input(title="MA 3 Type", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA3Source = input(title="MA 3 Source", type=input.source, defval=close)
MA4Period = input(7, title="MA 4 Period (SMA 7)")
MA4Type = input(title="MA 4 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA4Source = input(title="MA 4 Source", type=input.source, defval=close)
MA5Period = input(20, title="MA 5 Period (SMA 20)")
MA5Type = input(title="MA 5 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA5Source = input(title="MA 5 Source", type=input.source, defval=close)
MA6Period = input(50, title="MA 6 Period (SMA 50)")
MA6Type = input(title="MA 6 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA6Source = input(title="MA 6 Source", type=input.source, defval=close)
MA7Period = input(100, title="MA 7 Period (SMA 100)")
MA7Type = input(title="MA 7 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA7Source = input(title="MA 7 Source", type=input.source, defval=close)
MA8Period = input(200, title="MA 8 Period (SMA 200)")
MA8Type = input(title="MA 8 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA"])
MA8Source = input(title="MA 8 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(showema ? MA1 : na, color=#fff000, linewidth=3, title="MA 1 (EMA 10)")
plot(showema ? MA2 : na, color=color.green, linewidth=4, title="MA 2 (EMA 50)")
plot(showema ? MA3 : na, color=color.white, linewidth=4, title="MA 3 (EMA 200)")
plot(showema ? MA5 : na, color=#da00ff, linewidth=1, title="MA 5 (SMA 20)")
plot(showma ? MA4 : na, color=#e91e63, linewidth=1, title="MA 4 (SMA 7)") 
plot(showma ? MA6 : na, color=color.orange, linewidth=1, title="MA 6 (SMA 50)") 
plot(showma ? MA7 : na, color=color.blue, linewidth=1, title="MA 7 (SMA 100)")
plot(showma ? MA8 : na, color=#26a69a, linewidth=1, title="MA 8 (SMA 200)")


Oh yeah, I have added an signal that shows conversion/baseline cross on the Ichimoku cloud. You can delete that if you don’t like it, but sometimes it can be hard to spot that cross so I actually like it. You can either delete it from code by deleting line 29 and 30, or make it into a comment by addig 2 forward slashes in the beginning of the line, like this

or you can just make them totally transparent in the style settings 😀

Oh yeah, If you make any changes in the settings, don’t forget to “Save As Default“.

I hope this makes life a tiny bit better for someone.

Edit:

Oh yeah, everything I make is totally open source and free to use or change as one wishes, just give credit where credit is due and don’t charge anything for my work. Human knowledge belongs to the people! If you wanna send me a beer’s worth or something as a thank you, my bitcoin wallet is: 1M9yxwoGBiMebQktow8vQYV3J9EDAFwiYd and ETH wallet: 0x71Fa8219c055c7E865a8e5B499387c8781bFbd4b

I don’t expect anything, I just did this out of curiosity and to make my life a bit easier. Hopefully it can make someone else life a bit easier to. Much love!

Leave a Comment