Baekdoo compressed multi EMA box and its crossover indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © traderbaekdoosan

//@version=5
indicator("Baekdoo compressed multi EMA box and its crossover indicator", overlay=true)
disparity(period)=>
    close/ta.ema(close, period)*100

ratio=input(105)

A5=disparity(5)
A10=disparity(10)
A15=disparity(15)
A20=disparity(20)
A25=disparity(25)
A30=disparity(30)
A35=disparity(35)
A40=disparity(40)
A45=disparity(45)
A50=disparity(50)
A55=disparity(55)
A60=disparity(60)
A65=disparity(65)
A70=disparity(70)
A75=disparity(75)
A80=disparity(80)
A85=disparity(85)
A90=disparity(90)
A95=disparity(95)
A100=disparity(100)

MAXA=math.max(A5, A10, A15, A20, A25, A30, A35, A40, A45, A50, A55, A60, A65, A70, A75, A80, A85, A90, A95, A100)
MINA=math.min(A5, A10, A15, A20, A25, A30, A35, A40, A45, A50, A55, A60, A65, A70, A75, A80, A85, A90, A95, A100)

up=ta.valuewhen(MAXA/MINA*100 <ratio, ta.ema(close, 50)*MAXA/100, 1)
down=ta.valuewhen(MAXA/MINA*100 <ratio, ta.ema(close, 50)*MINA/100, 1)
boxup=plot(up, color=color.rgb(0, 200, 0, 90))
boxdown=plot(down, color=color.rgb(0, 200, 0, 90))
fill(boxup, boxdown, color.rgb(0, 200, 0, 50))

plotshape((ta.crossover(close, up) and volume>ta.highest(volume[1], 60)*5)? close : na , color=color.new(color.green, 0), style=shape.triangleup, location=location.belowbar, display=display.all, size=size.small)