Professional Documents
Culture Documents
Orderblock
Orderblock
//@version=5
indicator(shorttitle='Bagang Pivot Zones', title='Bagang Pivot Zones | Supply &
Demand, Support & Resistance', overlay=true)
// functions
get(arr, index) =>
index < array.size(arr) ? array.get(arr, index) : na
bounced(bounces) =>
status = array.get(bounces, 0)
array.set(bounces, 0, true)
status
// A. CORE
ceiling = math.max(high, close[1], open[1])
floor = math.min(low, close[1], open[1])
whiteSoldiers = bearish[3] and buying[2] and bullish[1] and bullish and close >
high[3]
blackCrows = bullish[3] and selling[2] and bearish[1] and bearish and close <
low[3]
// pivot setups
soaring = bullishEngulf or breakHigh or whiteSoldiers
tumbling = bearishEngulf or breakLow or blackCrows
reversal = switch
whiteSoldiers => not soaring[1] and not soaring[2]
blackCrows => not tumbling[1] and not tumbling[2]
breakHigh => not soaring[1] and (bearish[1] or bearish[2])
breakLow => not tumbling[1] and (bullish[1] or bullish[2])
continuation = switch
breakHigh => bullish[2] and close > high[2] and not bearish[1]
breakLow => bearish[2] and close < low[2] and not bullish[1]
// B. PIVOT ZONES
var buyzoneHigh = array.new_float(0)
var buyzoneLow = array.new_float(0)
var buyzoneTime = array.new_int(0)
var bounceUp = array.new_bool(0)
dacbar = switch
upturn => whiteSoldiers ? 3 : (breakHigh and selling[2] ? 2 : 1)
downturn => blackCrows ? 3 : (breakLow and buying[2] ? 2 : 1)
pivotbar = switch
upturn => whiteSoldiers ? 2 : (green[1] ? 1 : 0)
downturn => blackCrows ? 2 : (red[1] ? 1 : 0)
switch
upturn =>
// low at wick
pzLow := math.min(low[dacbar], low[pivotbar], low[1], low)
// high at wick or open
pzHigh := switch
close[pivotbar] > high[dacbar] => high[dacbar]
open[pivotbar] > open[dacbar] => open[pivotbar]
=> open[dacbar]
downturn =>
// high at wick
pzHigh := math.max(high[dacbar], high[pivotbar], high[1], high)
// low at wick or open
pzLow := switch
close[pivotbar] < low[dacbar] => low[dacbar]
open[pivotbar] < open[dacbar] => open[pivotbar]
=> open[dacbar]
replace = switch
overlap and upturn => bounced(bounceUp)
overlap and downturn => bounced(bounceDown)
downturn =>
array.unshift(sellzoneHigh, pzHigh)
array.unshift(sellzoneLow, pzLow)
array.unshift(sellzoneTime, time[dacbar])
array.unshift(bounceDown, false)
newbox(bg) =>
box.new(0, 0, 0, 0, xloc=xloc.bar_time, border_color=na, bgcolor=bg,
extend=extend.right)
for i = 0 to maxbox(na(close[1]))
array.push(buyBox, newbox(demand))
array.push(sellBox, newbox(supply))
// C. ALERTS
if brokenHigh
alert('Breakout', alert.freq_once_per_bar)
if brokenLow
alert('Breakdown', alert.freq_once_per_bar)
if upturn or downturn
setup = switch
whiteSoldiers => 'White Soldiers'
blackCrows => 'Black Crows'
breakHigh => bullishEngulf ? 'Engulf & Break High' : 'Break High'
breakLow => bearishEngulf ? 'Engulf & Break Low' : 'Break Low'
bullishEngulf => 'Bullish Engulf'
bearishEngulf => 'Bearish Engulf'
occurence = replace ? 'Replace' : (overlap ? 'Bounce' : 'Fresh')
message = setup + ' (' + occurence + ')'
alert(message, alert.freq_once_per_bar_close)