HEX Risk Metric (v0.1)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gerawrdog

//@version=4

//$HEX to the moon

study("HEX Risk Metric (v0.1)")

MA1 = ema(close, 21)
MA2 = sma(close, 50)
MA3 = sma(close, 100)
MA4 = sma(close, 200)
MA5 = sma(close, 300)
MA6 = sma(close, 600)

MA_x_1 = offset(MA1,7)
MA_x_2 = offset(MA2,7)
MA_x_3 = offset(MA3,7)
MA_x_4 = offset(MA4,7)
MA_x_5 = offset(MA5,7)
MA_x_6 = offset(MA6,7)


dydx_1 = (MA1-MA_x_1)/MA1
dydx_2 = (MA2-MA_x_2)/MA2
dydx_3 = (MA3-MA_x_3)/MA3
dydx_4 = (MA4-MA_x_4)/MA4
dydx_5 = (MA5-MA_x_5)/MA5
dydx_6 = (MA6-MA_x_6)/MA6


risk1 = ((dydx_1+0.05443673772)*2.31790786654)
risk2 = ((dydx_2+0.05443673772)*2.31790786654)
risk3 = ((dydx_3+0.05443673772)*2.31790786654)
risk4 = ((dydx_4+0.05443673772)*2.31790786654)
risk5 = ((dydx_5+0.05443673772)*2.31790786654)
risk6 = ((dydx_6+0.05443673772)*2.31790786654)


ft = input(0.8,title="Filter Top",step=0.1)
fb = input(0.1,title="Filter Top",step=0.1)

ft2 = input(0.8,title="Filter Top",step=0.1)
fb2 = input(0,title="Filter Top",step=0.1)

hline(ft, title='Filter Top', color=color.white, linewidth=1)
hline(fb, title='Filter Bottom', color=color.white, linewidth=1)

filter1 = risk1 > ft2 ? color.orange : risk1 < fb2 ? color.green : color.aqua
filter2 = risk2 > ft2 ? color.orange : risk2 < fb2 ? color.green : color.aqua
filter3 = risk3 > ft2 ? color.purple : risk3 < fb2 ? color.green : color.blue
filter4 = risk4 > ft ? color.purple : risk4 < fb ? color.yellow : color.blue
filter5 = risk5 > ft ? color.purple : risk5 < fb ? color.yellow : color.white
filter6 = risk6 > ft ? color.purple : risk6 < fb ? color.yellow : color.white


plot(risk1, title="HEX Risk Metric (21)",linewidth=1,color=filter1)
plot(risk2, title="HEX Risk Metric (50)",linewidth=2,color=filter2)
plot(risk3, title="HEX Risk Metric (100)",linewidth=2,color=filter3)
plot(risk4, title="HEX Risk Metric (200)",linewidth=3,color=filter4)
plot(risk5, title="HEX Risk Metric (300)",linewidth=3,color=filter5)
plot(risk6, title="HEX Risk Metric (600)",linewidth=3,color=filter6)