Professional Documents
Culture Documents
SD
SD
SD
indicator("S&D ZONES"
, overlay = true
, max_labels_count = 500
, max_lines_count = 500
, max_boxes_count = 500
, max_bars_back = 500)
max_bars_back(time, 500)
//-----------------------------------------------------------------------------{
//Constants
//-----------------------------------------------------------------------------{
int DEMAND_ZONE = 1
int SUPPLY_ZONE = 2
int TBD_ZONE = 0
//-----------------------------------------------------------------------------{
//Settings
//-----------------------------------------------------------------------------{
// -- Indecision ----
indecision_factor = input.int(2, 'Min. Factor', minval = 1, group = "Indecision")
volume_periods = input.int(26, 'Previous Periods', minval = 1, group =
"Indecision")
volume_chg = input.int(10, 'Volume Change (%)', minval = 1, group = "Indecision")
confirm_bars = input.int(2, 'Confirmation Bars', minval = 1, group = 'Indecision')
invalidation = input.string('Wick', 'Invalidation Method', options = ['Close',
'Wick'], group = "Indecision")
// -- Zones ----
showlast = input.int(10, 'Show Last', minval = 1, group = 'Zones')
demand_zone_css = input.color(color.new(#66bb6a, 70), 'Demand', inline = "Zones",
group = 'Zones')
supply_zone_css = input.color(color.new(#f77c80, 70), 'Supply', inline = "Zones",
group = 'Zones')
indecision_zone_css = input.color(color.new(#777575, 70), 'Indecision', inline =
"Zones",group = 'Zones')
text_size = input.string('Small', 'Text Size', options = ['Tiny', 'Small',
'Normal'], group = "Zones")
//Global variables
//-----------------------------------------------------------------------------{
var zone_boxes = array.new_box(0)
var zone_labels = array.new_label(0)
type Zone
float top
float bottom
float volume
int left
int type = 0
color css
int reached = 0
int bars_outside = 0
//------------------------------------------------------------------
// FUNCTIONS
//-----------------------------------------------------------------
get_volume(include_current_bar, bars) =>
past_vol = array.new_float(0)
for i = include_current_bar ? 0: 1 to bars
array.push(past_vol, volume[i])
array.avg(past_vol)
is_indecision_bar() =>
//Is an indecision candle?
float high_change = 0.
float low_change = 0.
float body_change = math.abs((close - open) / open)
confirm_zone(zone) =>
valid_zone = true
new_volume = get_volume(true, confirm_bars)
zone.volume := math.round((new_volume - zone.volume) / zone.volume * 100, 0)
if math.max(open, close) > zone.top
zone.type := DEMAND_ZONE
zone.css := demand_zone_css
else if math.min(open, close) < zone.bottom
zone.type := SUPPLY_ZONE
zone.css := supply_zone_css
if zone.type == TBD_ZONE
label.set_text(get_label, "")
else
label.set_text(get_label, "Volume change: " + str.tostring(zone.volume)
+ "%\nReached: " + str.tostring(zone.reached))
//------------------------------------------------------------------
// CALCULATE ZONES
//------------------------------------------------------------------
if barstate.isfirst
for i = 0 to showlast - 1
array.push(zone_boxes, box.new(na,na,na,na, xloc = xloc.bar_time , extend =
extend.right))
array.push(zone_labels, label.new(na,na,na, size = label_size, style =
label.style_none))
if barstate.isconfirmed
if is_indecision_bar()
period_volume = get_volume(include_current_bar = false, bars =
volume_periods)
array.push(zones, Zone.new(top = high, bottom = low, volume =
period_volume, left = time, css= indecision_zone_css))
zone.reached += 1
price_enter_supply_zone := true
if price_enter_demand_zone or price_enter_supply_zone
zone.bars_outside := 0
last_zone_reached := zone
if barstate.islast
int zones_size = array.size(zones)
if zones_size > 0
display_zones(zone_boxes, zone_labels, zones, showlast, zones_size)
//------------