Professional Documents
Culture Documents
//Data Curation
res = ''
[copen, chigh, clow, cclose] = request.security(syminfo.tickerid, res, [open, high, low, close],
barmerge.gaps_on, barmerge.lookahead_off)
// Color Scheme
bullcolor = colors == 'DARK' ? color.rgb (255,255,255,50) : color.rgb(0,255,0,50)
bearcolor = colors == 'DARK' ? color.rgb(0,0,255,50) : color.rgb(255,0,0,50)
bullcolor2 = colors == 'DARK' ? color.white : color.green
bearcolor2 = colors == 'DARK' ? color.blue : color.red
int upcandles = 0
for i = 1 to periods by 1
upcandles += (cclose[i] > copen[i] ? 1 : 0) // Determine color of subsequent candles (must all
be green to identify a valid Bearish OB)
upcandles
OB_bull = bullishOB and upcandles == periods and relmove // Identification logic (red OB
candle & subsequent green candles)
OB_bull_chigh = OB_bull ? chigh[ob_period] : na // Determine OB upper limit (Open or High
depending on input)
OB_bull_clow = OB_bull ? clow[ob_period] : na // Determine OB clower limit (Low)
OB_bull_avg = (OB_bull_chigh + OB_bull_clow) / 2 // Determine OB middle line
int downcandles = 0
for i = 1 to periods by 1
downcandles += (cclose[i] < copen[i] ? 1 : 0) // Determine color of subsequent candles (must
all be red to identify a valid Bearish OB)
downcandles
OB_bear = bearishOB and downcandles == periods and relmove // Identification logic (green
OB candle & subsequent green candles)
OB_bear_chigh = OB_bear ? chigh[ob_period] : na // Determine OB upper limit (High)
OB_bear_clow = OB_bear ? clow[ob_period] : na // Determine OB clower limit (Open or Low
depending on input)
OB_bear_avg = (OB_bear_clow + OB_bear_chigh) / 2 // Determine OB middle line
// Plotting
plotshape(OB_bull, title='Bullish OB', style=shape.triangleup, color=bullcolor, textcolor=bullcolor,
size=size.tiny, location=location.belowbar, offset=-ob_period, text='Bull') // Bullish OB Indicator
bull1 = plot(OB_bull_chigh, title='Bullish OB High', style=plot.style_linebr, color=bullcolor,
offset=-ob_period, linewidth=2) // Bullish OB Upper Limit
bull2 = plot(OB_bull_clow, title='Bullish OB Low', style=plot.style_linebr, color=bullcolor,
offset=-ob_period, linewidth=2) // Bullish OB Lower Limit
fill(bull1, bull2, color=bullcolor, title='Bullish OB fill') // Fill Bullish OB
plotshape(OB_bull_avg, title='Bullish OB Average', style=shape.cross, color=bullcolor,
size=size.small, location=location.absolute, offset=-ob_period) // Bullish OB Average
sync = time_close(res)
// Color Scheme
bullcolor3 = colors2 == 'DARK' ? color.white : color.green
bearcolor3 = colors2 == 'DARK' ? color.blue : color.red
int upcandles2 = 0
for i = 0 to periods2 by 1
upcandles2 += (close[i] > open[i] ? 1 : 0) // Determine color of subsequent candles (must all
be green to identify a valid Bearish OB2)
upcandles2
OB_bull2 = bullishOB2 and upcandles2 == periods2 and relmove2 // Identification logic (red OB
candle & subsequent green candles)
OB_bull_high2 = OB_bull2 ? usewicks2 ? high[ob_period2] : open[ob_period2] : na //
Determine OB2 upper limit (Open or High depending on input)
OB_bull_low2 = OB_bull2 ? low[ob_period2] : na // Determine OB2 lower limit (Low)
OB_bull_avg2 = (OB_bull_high2 + OB_bull_low2) / 2 // Determine OB2 middle line
int downcandles2 = 0
for i = 0 to periods2 by 1
downcandles2 += (close[i] < open[i] ? 1 : 0) // Determine color of subsequent candles (must
all be red to identify a valid Bearish OB2)
downcandles2
OB_bear2 = bearishOB2 and downcandles2 == periods2 and relmove2 // Identification logic
(green OB2 candle & subsequent green candles)
OB_bear_high2 = OB_bear2 ? high[ob_period2] : na // Determine OB2 upper limit (High)
OB_bear_low2 = OB_bear2 ? usewicks2 ? low[ob_period2] : open[ob_period2] : na //
Determine OB2 lower limit (Open or Low depending on input)
OB_bear_avg2 = (OB_bear_low2 + OB_bear_high2) / 2 // Determine OB middle line
// Plotting
if OB_bull2
alert("Buy Signal\n(Bullish Order Block):" +
str.tostring(close),freq=alert.freq_once_per_bar_close)
if OB_bear2
alert("Sell Signal\n(Bearish Order Block):" +
str.tostring(close),freq=alert.freq_once_per_bar_close)
line.delete(linebull5)
linebull5 := line.new(x1=bar_index, y1=OB_bull_high2, x2=bar_index - 1, y2=OB_bull_high2,
extend=extend.left, color=bullcolor3, style=line.style_dashed, width=1)
line.delete(linebull6)
linebull6 := line.new(x1=bar_index, y1=OB_bull_low2, x2=bar_index - 1, y2=OB_bull_low2,
extend=extend.left, color=bullcolor3, style=line.style_dashed, width=1)
linebull6
line.delete(linebear5)
linebear5 := line.new(x1=bar_index, y1=OB_bear_high2, x2=bar_index - 1,
y2=OB_bear_high2, extend=extend.left, color=bearcolor3, style=line.style_dashed, width=1)
line.delete(linebear6)
linebear6 := line.new(x1=bar_index, y1=OB_bear_low2, x2=bar_index - 1,
y2=OB_bear_low2, extend=extend.left, color=bearcolor3, style=line.style_dashed, width=1)
linebear3
if OB_bull_avg2 > 0
latest_bull_avg := OB_bull_avg2
latest_bull_avg
if OB_bull_low2 > 0
latest_bull_low := OB_bull_low2
latest_bull_low
if OB_bear_high2 > 0
latest_bear_high := OB_bear_high2
latest_bear_high
if OB_bear_avg2 > 0
latest_bear_avg := OB_bear_avg2
latest_bear_avg
if OB_bear_low2 > 0
latest_bear_low := OB_bear_low2
latest_bear_low
// Plot invisible characters to be able to show the values in the Data Window
plotchar(latest_bull_high, char=' ', location=location.abovebar, color=color.new(#777777, 100),
size=size.tiny, title='Latest Bull High')
plotchar(latest_bull_avg, char=' ', location=location.abovebar, color=color.new(#777777, 100),
size=size.tiny, title='Latest Bull Avg')
plotchar(latest_bull_low, char=' ', location=location.abovebar, color=color.new(#777777, 100),
size=size.tiny, title='Latest Bull Low')
plotchar(latest_bear_high, char=' ', location=location.abovebar, color=color.new(#777777, 100),
size=size.tiny, title='Latest Bear High')
plotchar(latest_bear_avg, char=' ', location=location.abovebar, color=color.new(#777777, 100),
size=size.tiny, title='Latest Bear Avg')
plotchar(latest_bear_low, char=' ', location=location.abovebar, color=color.new(#777777, 100),
size=size.tiny, title='Latest Bear Low')
//InfoPanel for latest Order Blocks
panel_text = '\n' + title + '\n' + row0 + '\n' + row1 + '\n' + row2 + '\n' + row3 + '\n' + row4 + '\n\n' +
row5 + '\n' + row6 + '\n' + row7 + '\n'
if info_pan
draw_InfoPanel(panel_text, info_panel_x, info_panel_y, size.normal)
var vartooltip = 'Indicator to help identifying instituational Order Blocks. Often these blocks signal
the beginning of a strong move, but there is a high probability, that these prices will be revisited
at a later point in time again and therefore are interesting levels to place limit orders. \nBullish
Order block is the last down candle before a sequence of up candles. \nBearish Order Block is
the last up candle before a sequence of down candles. \nIn the settings the number of required
sequential candles can be adjusted. \nFurthermore a %-threshold can be entered which the
sequential move needs to achieve in order to validate a relevant Order Block. \nChannels for
the last Bullish/Bearish Block can be shown/hidden.'
// === Print Label ===
var label l_docu = na
label.delete(l_