z_score_bgd
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © crashout75
//crashout@protonmail.com

//@version=5
indicator(title = "z_score_bgd", overlay = true)

window = input(99, title="window")
int window2 = na
vSYMBOL = syminfo.ticker

print(txt) =>
    // Create label on the first bar.
    var lbl = label.new(bar_index, na, txt, xloc.bar_index, yloc.price, color(na), label.style_none, color.gray, size.large, text.align_left)
    // On next bars, update the label's x and y position, and the text it displays.
    label.set_xy(lbl, bar_index, ta.highest(100)[1])
    label.set_text(lbl, txt)

window2 := if (vSYMBOL == 'ATOMBTC')
    18
else
    window2 := if (vSYMBOL == 'AVAXBTC')
        21
    else
        window2 := if (vSYMBOL == 'ETHBTC')
            18
        else 
            window2 := if (vSYMBOL == 'FTMBTC')
                11
            else
                window2 := if (vSYMBOL == 'MATICBTC')
                    11
                else
                    window2 := if (vSYMBOL == 'SOLBTC')
                        11
                    else
                        window2 := if (vSYMBOL == 'SOLETH')
                            16
                        else
                            20


window2 := if (window == 99)
    window2
else
    window
    
print("\n" + "(" + str.tostring(window2) + ")")
    
vSMA = ta.sma(close,window2)
vSTDDEV = ta.stdev(close,window2,true)
vZ = (close-vSMA)/vSTDDEV

bgcolor(vZ < -1 ? color.new(color.green,90):color.new(color.white,100) )
bgcolor(vZ < -2 ? color.new(color.green,80):color.new(color.white,100) )
bgcolor(vZ > 1 ? color.new(color.red,90):color.new(color.white,100) )
bgcolor(vZ > 2 ? color.new(color.red,80):color.new(color.white,100) )

plot(vSMA,color=color.blue)