Top - Bottom Using MA
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jadeja_rajdeep

//@version=5
indicator("Top - Bottom From MA",precision = 3)
length=input.int(50,"MA Length",20,252,1,group = "Inputs")
h_l_length=input.int(63,"Highest / Lowest Value Length",20,252,1,group = "Inputs")
p_diff=input.float(0.15,"Diffrence Between High and Low point",0.10,0.50,0.01,group = "Inputs")

sma=ta.sma(ohlc4,length)
ratio=close/sma
h=ta.highest(ratio,h_l_length)
l=ta.lowest(ratio,h_l_length)
m=math.avg(h,l)
msma=ta.linreg(ratio,length,0)
plot(ratio,color =(ratio > msma? color.green : color.red))
hl_color=((h-l) > p_diff ? color.gray : color.orange)
plot(h,color = hl_color)
plot(msma,color = (msma > msma[1] and msma >= l ? color.green : color.red))
plot(m,color = hl_color)
plot(l,color = hl_color)
