Hi Guys! My name is Matteo Taronna, I currently work as an analyst for Bybit! I need some of your help with this topic.

This is a small code that automatically puts 50 well traced OB in my chart, but I have a problem:

I want to put a trade with strategy.entry() when the candle sticks touch the OB in both direction, in the code down below, how you would modified it to efectively make the entry?

I`ve tried something that is in bold text but it didnt work well.

Thanks for your help team!


plotTextOB = input.bool(defval=true, title='Plot Text inside OB', group='Order Blocks', inline='OB sets')
bearboxcolor = input.color(defval=#a86161, title=Bearish OB Box, inline='customcolor', group=order Blocks)
bullboxcolor = input.color(defval=#004d40, title=Bullish OB Box, inline='customcolor', group=order Blocks)
showOBboxes = input(true, title=Show OB Boxes,group=Order Blocks)
adtransp = input.int(defval=65, title=Box Transparency, minval=1, maxval=100, group=Order Blocks)
adboxcount = input.int(defval=50, title=Maximum Box Displayed, minval=1, maxval=200, group=Order Blocks)

plotHVB = input.bool(defval=true, title='Plot HVB', group='High Volume Bar', tooltip='A candle where the average volume is higher than last few bars.')
hvbBullColor = input.color(defval=color.green, title='Bullish HVB Color', inline='Set Custom Color', group='High Volume Bar')
hvbBearColor = input.color(defval=color.red, title='Bearish HVB Color', inline='Set Custom Color', group='High Volume Bar')
hvbEMAPeriod = input.int(defval=12, minval=1, title='Volume EMA Period', group='High Volume Bar')
hvbMultiplier = input.float(defval=1.5, title='Volume Multiplier', minval=1, maxval=100, group='High Volume Bar')

//Box Labels
var string _obLabel = OB
var string _empty = ""

//Functions
isUp(index) =>
close[index] > open[index]

isDown(index) =>
close[index] < open[index]

//**********************************************************************************************************************************************************************************//

//Inputs
highBarNext = high
lowBarNext = low
highBarPrevious = high[2]
lowBarPrevious = low[2]
openBarPrevious = open[2]
closeBarPrevious = close[2]
openBarCurrent = open[1]
closeBarCurrent = close[1]
int offset = 2
bar_index_ = bar_index[offset]
bearCandlecolor = #a86161
bullcandlecolor = #004d40
adtranspCandle = 65

//If the Candle in index of 1 (the candle being detected as engulfing and imbalanced) and the next candle does not fill the imbalance, then a signal is generated.
bullishEngulfing = openBarCurrent <= closeBarPrevious and openBarCurrent < openBarPrevious and
closeBarCurrent > openBarPrevious and lowBarNext > highBarPrevious
bearishEngulfing = openBarCurrent >= closeBarPrevious and openBarCurrent > openBarPrevious and
closeBarCurrent < openBarPrevious and highBarNext < lowBarPrevious

//Plot OB Candles
barcolor(bullishEngulfing? color.new(bullcandlecolor,adtranspCandle) : na, offset=-2)
barcolor(bearishEngulfing? color.new(bearCandlecolor,adtranspCandle) : na, offset=-2)

//Box Variables
var box[] bearboxarray = array.new_box()
var box[] bullboxarray = array.new_box()

//Box Color Variables
var color adbearboxcolor = color.new(bearboxcolor, adtransp)
var color adbullboxcolor = color.new(bullboxcolor, adtransp)
var color adbearborderboxcolor = color.new(bearboxcolor, adtransp)
var color adbullborderboxcolor = color.new(bullboxcolor, adtransp)

//Bearish OB Box Calculation
f_choppedoffbear(bearboxarray) =>
if (array.size(bearboxarray) > 0)
for i = array.size(bearboxarray) - 1 to 0
cutbox = array.get(bearboxarray, i)
boxlowzone = box.get_bottom(cutbox)
boxhighzone = box.get_top(cutbox)
boxrightzone = box.get_right(cutbox)
if (na or (bar_index - 1 == boxrightzone and not ((high > boxlowzone and low < boxlowzone) or (high > boxhighzone and low < boxhighzone))))
box.set_right(array.get(bearboxarray, i), bar_index)
if bar_index - 1 == boxrightzone and (high > boxlowzone and low < boxlowzone) or (high > boxhighzone and low < boxhighzone)
strategy.entry(SHORT OB, strategy.short)

//Bearish OB Box Plotting
if (bearishEngulfing and showOBboxes)
boxhighzone = high[2] > high[1] ? high[2] : high [1]
boxlowzone = open[2]
bearbox = box.new(bar_index_, boxhighzone, bar_index, boxlowzone, border_color=adbearborderboxcolor, border_style=line.style_dashed, bgcolor=adbearboxcolor,
text=plotTextOB ? _obLabel : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=size.tiny, text_color=color.gray)
if (array.size(bearboxarray) > adboxcount)
box.delete(array.shift(bearboxarray))
array.push(bearboxarray, bearbox)

f_choppedoffbear(bearboxarray)

//Bullish OB Box Calculation

f_choppedoffbull(bullboxarray) =>
if (array.size(bullboxarray) > 0)
for i = array.size(bullboxarray) - 1 to 0
cutbox = array.get(bullboxarray, i)
boxlowzone = box.get_bottom(cutbox)
boxhighzone = box.get_top(cutbox)
boxrightzone = box.get_right(cutbox)
if (na or (bar_index - 1 == boxrightzone and not ((high > boxlowzone and low < boxlowzone) or (high > boxhighzone and low < boxhighzone))))
box.set_right(array.get(bullboxarray, i), bar_index)

//Bullish OB Box Plotting

if (bullishEngulfing and showOBboxes)
boxlowzone = low[1] < low[2] ? low [1] : low [2]
boxhighzone = open[2]
bullbox = box.new(bar_index_, boxhighzone, bar_index, boxlowzone, border_color=adbullborderboxcolor, border_style=line.style_dashed, bgcolor=adbullboxcolor,
text=plotTextOB ? _obLabel : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=size.tiny, text_color=color.gray)
if (array.size(bullboxarray) > adboxcount)
box.delete(array.shift(bullboxarray))
array.push(bullboxarray, bullbox)

f_choppedoffbull(bullboxarray)