OWRS Volatililility
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Eliza123123

//@version=5
indicator('The Ocean makes Waves which turn to Ripples which wash onto the Sand', overlay=false)

referenceOCEAN = input('BINANCE:OCEANUSDTPERP', 'Reference market')
referenceWAVES = input('BINANCE:WAVESUSDTPERP', 'Reference market')
referenceXRP = input('BINANCE:XRPUSDTPERP', 'Reference market')
referenceSAND = input('BINANCE:SANDUSDTPERP', 'Reference market')

a = math.abs(high-low) - (math.abs(high-low))[1]

rdOCEAN = request.security(symbol=referenceOCEAN, timeframe=timeframe.period, expression=a*27)
rdWAVES = request.security(symbol=referenceWAVES, timeframe=timeframe.period, expression=a)
rdXRP = request.security(symbol=referenceXRP, timeframe=timeframe.period, expression=a*27)
rdSAND = request.security(symbol=referenceSAND, timeframe=timeframe.period, expression=a*27)

rdOCEANChaos = (rdOCEAN + rdOCEAN[1] + rdOCEAN[2] + rdOCEAN[3])
rdWAVESChaos = (rdWAVES + rdWAVES[1] + rdWAVES[2] + rdWAVES[3])
rdXRPChaos = (rdXRP + rdXRP[1] + rdXRP[2] + rdXRP[3])
rdSANDChaos = (rdSAND + rdSAND[1] + rdSAND[2] + rdSAND[3])

ANP = (rdOCEANChaos + rdWAVESChaos + rdXRPChaos + rdSANDChaos) / 4

stdevANP = ta.stdev(ANP, 27)

plot(ANP + stdevANP, color = color.new(color.fuchsia, 0))
plot(ANP + (2*stdevANP), color = color.new(#FF0051, 0))
plot(ANP + (3*stdevANP), color = color.new(#FF00BB, 0))
plot(ANP + (4*stdevANP), color = color.new(color.lime, 0))

plot(ANP - stdevANP, color = color.new(color.fuchsia, 0))
plot(ANP - (2*stdevANP), color = color.new(#FF0051, 0))
plot(ANP - (3*stdevANP), color = color.new(#FF00BB, 0))
plot(ANP - (4*stdevANP), color = color.new(color.lime, 0))


plot(rdOCEANChaos, color = (rdOCEANChaos > ANP + (4*stdevANP)) or (rdOCEANChaos < ANP - (4*stdevANP))? color.new(color.yellow, 0) : color.new(#0000FF, 0), style = plot.style_stepline_diamond)
plot(rdWAVESChaos, color = (rdWAVESChaos > ANP + (4*stdevANP)) or (rdWAVESChaos < ANP - (4*stdevANP))? color.new(color.yellow, 0) : color.new(color.white, 0), style = plot.style_stepline_diamond)
plot(rdXRPChaos, color = (rdXRPChaos > ANP + (4*stdevANP)) or (rdXRPChaos < ANP - (4*stdevANP))? color.new(color.yellow, 0) : color.new(#00FFFB, 0), style = plot.style_stepline_diamond)
plot(rdSANDChaos, color = (rdSANDChaos > ANP + (4*stdevANP)) or (rdSANDChaos < ANP - (4*stdevANP))? color.new(color.yellow, 0) : color.new(#E1AA80, 0), style = plot.style_stepline_diamond)

yellowbg = 0
if (rdOCEANChaos > ANP + (4*stdevANP)) or (rdOCEANChaos < ANP - (4*stdevANP)) or (rdWAVESChaos > ANP + (4*stdevANP)) or (rdWAVESChaos < ANP - (4*stdevANP)) or (rdXRPChaos > ANP + (4*stdevANP)) or (rdXRPChaos < ANP - (4*stdevANP)) or (rdSANDChaos > ANP + (4*stdevANP)) or (rdSANDChaos < ANP - (4*stdevANP)) 
    yellowbg := 1
bgcolor(color = yellowbg == 1 ? color.yellow : color.blue, transp = 75)

