Halfback + One-Time-Framing Bars
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OasisTrading

//@version=4
study(title="Halfback + One-Time-Framing Bars", shorttitle="HB + OTF Bars", overlay=true)

halfbackplot = input(true, title="Enable Halfback")
otfplot = input(true, title="Enable One-Time-Framing")

res = input(title="Resolution", type=input.resolution, defval="30")

highprice = security(syminfo.tickerid, res, high)
lowprice = security(syminfo.tickerid, res, low)

Halfback = avg(highprice,lowprice)



Halfbackline = valuewhen(halfbackplot==true and Halfback, avg(highprice,lowprice), 0)

colorrgb = color.rgb(236,64,122)

plot(halfbackplot ? Halfbackline : na, title="Halfback", color=colorrgb, style=plot.style_stepline, linewidth=2, transp=0, offset=1)


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//one-time-framing

onetimeframeup= (highprice > highprice[1]) and (lowprice > lowprice[1]) 
onetimeframedown= (highprice < highprice[1]) and (lowprice < lowprice[1]) 

plotshape(otfplot ? onetimeframeup : na,title= "OTF Bullish", style=shape.triangleup,location=location.abovebar,color=color.blue,size=size.tiny)
plotshape(otfplot ? onetimeframedown : na,title= "OTF Bearish", style=shape.triangledown,location=location.belowbar,color=color.orange,size=size.tiny)


