Beakdoo swing trading box
// 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("Beakdoo swing trading box", overlay=true)

AA=high[1]>ta.highest(close[2], 20)
// cross up highest close till preday with Period 20 or 60

// starting point of 5 kiss or crossup 20 eavg
BB=(close> ta.ema(close, 5)) or ta.crossover(close, ta.ema(close,20))

BBB=BB or BB[1] or BB[2]

// crossup highest volume
CC=volume[1]>ta.highest(volume[2], 20)
CCC=CC or CC[1] or CC[2]

// neg candle (or tail) // buy signal
DD=open>close and close<(math.abs(close[1]-open[1])*2/3+math.min(close[1],open[1]))

//support eavg(c, 20) //lower bound
EE= math.max(ta.ema(close, 5), ta.ema(close,20))

FF=(close>(ta.highest(high[25],9)+ta.lowest(low[25],9)+ta.highest(high[25],26)+ta.lowest(low[25],26))/4 ) and (close>(ta.highest(high[25],52)+ta.lowest(low[25],52))/2)


condition=AA and BBB and CCC and DD and FF

line1=ta.valuewhen(condition, (math.abs(close[1]-open[1])*2/3+math.min(close[1], open[1])), 1)

line2=ta.valuewhen(condition, math.max((math.abs(close[1]-open[1])*2/3+math.min(close[1], open[1]))*0.95, EE), 1)

p11=plot(line1, color=color.new(color.orange, 20), title='upper box')
p22=plot(line2, color=color.new(color.orange, 20), title='bottom box')
fill(p11, p22, color=color.new(color.orange, 20))