PRAVIN HAJARE SMALL ENTRY & SMALL EXIT
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ceyhun

//@version=4

study("PRAVIN HAJARE SMALL ENTRY & SMALL EXIT", overlay=true)

boxp = input(defval=5, title="Length", minval=1, maxval=500)

LL = lowest(low, boxp)
k1 = highest(high, boxp)
k2 = highest(high, boxp - 1)
k3 = highest(high, boxp - 2)

NH = valuewhen(high > k1[1], high, 0)
box1 = k3 < k2
TopBox = valuewhen(barssince(high > k1[1]) == boxp - 2 and box1, NH, 0)
BottomBox = valuewhen(barssince(high > k1[1]) == boxp - 2 and box1, LL, 0)

//plot(TopBox, linewidth=2, color=#4CAF50, title="TBbox")
//plot(BottomBox, linewidth=2, color=#FF0000, title="BBbox")

Buy = crossover(close, TopBox)
Sell = crossunder(close, BottomBox)

alertcondition(Buy, title="Buy Signal", message="B")
alertcondition(Sell, title="Sell Signal", message="S")

plotshape(Buy, style=shape.labelup, location=location.belowbar, color=#4CAF50, size=size.tiny, title="Buy Signal", text="B", textcolor=color.black)
plotshape(Sell, style=shape.labeldown, location=location.abovebar, color=#FF0000, size=size.tiny, title="Sell Signal", text="S", textcolor=color.black)
