Money Supply Index (MSI) by zdmre
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © zdmre

//@version=5
indicator("Money Supply Index (MSI) by zdmre")

MS2 = input.symbol("USM2", "Money Supply")
MS = request.security(MS2, "D", close)
crl = input.symbol("NASDAQ:NDX", "Relational Symbol")
vs = request.security(crl, "D", close)

mainsym = input.bool(defval=true, title="Symbol on Chart", tooltip="if Enabled; The Relationship between the Money Supply and Symbol on Chart. Else; MS relation with Relational Symbol" )
rate = mainsym ? MS/close : MS/vs

len = input.int(14, minval=1, title='Length')
up = ta.rma(math.max(ta.change(rate), 0), len)
down = ta.rma(-math.min(ta.change(rate), 0), len)
msi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + down / up)

band1 = hline(70, "Upper Band", color=#787B86)
bandhl = hline(60, "HL Band", color=color.new(#ff3d3d, 70))
bandlh = hline(40, "LH Band", color=color.new(#4cff3d, 70))
band0 = hline(30, "Lower Band", color=#787B86)

ob= ta.cross(msi, 70) == 1 and msi >= 70
os = ta.cross(msi, 30) == 1 and msi <= 30

fill(band1, bandhl, color=color.new(#ff0000, 95), title="Background Upper Band")
fill(bandlh, bandhl, color=color.rgb(126, 87, 194, 90), title="Background Neutral")
fill(band0, bandlh, color=color.new(#32ff00, 95), title="Background Lower Band")
plot(msi, 'MSI', color=color.new(#7E57C2, 0))
plot(ob ? msi : na ,title='Overbought', style=plot.style_circles, color=color.new(color.red, 0), linewidth=5)
plot(os ? msi : na ,title='Oversold ', style=plot.style_circles, color=color.new(color.green, 0), linewidth=5)

var label1 = label.new(100, 65, text="not to Buy!", style=label.style_text_outline, size=size.large, color=color.new(#ff0000, 75))
label.set_xloc(label1, time[50], xloc.bar_time)

var label2 = label.new(0, 35, text="not to Sell!", style=label.style_text_outline, size=size.large, color=color.new(#32ff00, 75))
label.set_xloc(label2, time[50], xloc.bar_time)