There are 4 types of supply and demand zones.
- Rally Base Rally
- Rally Base Rally
- Rally Base Drop
- Drop Base Drop
If you have any questions please let me know below
Below is a code for the indicator
Code: Select all
//@version=5
indicator("Supply and Demand Zones (RBR, RBD, DBR, DBD)", overlay=true)
// Function to calculate body-to-wick ratio
body_to_wick_ratio(candle_open, candle_close, candle_high, candle_low) =>
body = math.abs(candle_close - candle_open)
wick = math.abs(candle_high - candle_low) - body
ratio = wick > 0 ? body / wick : 0
ratio
// Define body-to-wick ratio thresholds
rally_drop_ratio_threshold = 0.7
base_ratio_threshold = 0.3
candle_range(candle_high, candle_low) =>
crange = candle_high - candle_low
crange
// Function for Rally Base Rally (RBR) Bullish
is_rbr_bullish() =>
// Rally Candle 1 (Bullish)
body_to_wick_ratio(open[2], close[2], high[2], low[2]) > rally_drop_ratio_threshold and
close[2] > open[2] and
// Base Candle (Bearish)
body_to_wick_ratio(open[1], close[1], high[1], low[1]) < base_ratio_threshold and
close[1] < open[1] and
candle_range(high[1], low[1]) < candle_range(high[2], low[2]) and candle_range(high[1], low[1]) < candle_range(high, low) and
// Rally Candle 2 (Bullish)
body_to_wick_ratio(open, close, high, low) > rally_drop_ratio_threshold and
close > open
// Function for Drop Base Rally (DBR) Bearish
is_dbr_bearish() =>
// Drop Candle 1 (Bearish)
body_to_wick_ratio(open[2], close[2], high[2], low[2]) > rally_drop_ratio_threshold and
close[2] < open[2] and
// Base Candle (Bearish)
body_to_wick_ratio(open[1], close[1], high[1], low[1]) < base_ratio_threshold and
close[1] < open[1] and
candle_range(high[1], low[1]) < candle_range(high[2], low[2]) and candle_range(high[1], low[1]) < candle_range(high, low) and
// Rally Candle 2 (Bullish)
body_to_wick_ratio(open, close, high, low) > rally_drop_ratio_threshold and
close > open
// Function for Drop Base Drop (DBD) Bearish
is_dbd_bearish() =>
// Drop Candle 1 (Bearish)
body_to_wick_ratio(open[2], close[2], high[2], low[2]) > rally_drop_ratio_threshold and
close[2] < open[2] and
// Base Candle (Bearish)
body_to_wick_ratio(open[1], close[1], high[1], low[1]) < base_ratio_threshold and
close[1] < open[1] and
candle_range(high[1], low[1]) < candle_range(high[2], low[2]) and candle_range(high[1], low[1]) < candle_range(high, low) and
// Drop Candle 2 (Bearish)
body_to_wick_ratio(open, close, high, low) > rally_drop_ratio_threshold and
close < open
// Function for Rally Base Drop (RBD) Bullish
is_rbd_bullish() =>
// Rally Candle 1 (Bullish)
body_to_wick_ratio(open[2], close[2], high[2], low[2]) > rally_drop_ratio_threshold and
close[2] > open[2] and
// Base Candle (Bearish)
body_to_wick_ratio(open[1], close[1], high[1], low[1]) < base_ratio_threshold and
close[1] < open[1] and
candle_range(high[1], low[1]) < candle_range(high[2], low[2]) and candle_range(high[1], low[1]) < candle_range(high, low) and
// Drop Candle 2 (Bearish)
body_to_wick_ratio(open, close, high, low) > rally_drop_ratio_threshold and
close < open
// Plot labels and lines for RBR, RBD, DBR, DBD patterns only on the base candle
if is_rbr_bullish()
label.new(bar_index[1], low[1], "RBR", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small)
// Draw the supply/demand zone as a rectangle at the base candle high and low
box.new(bar_index[1], high[1], bar_index, low[1], border_color=color.green, bgcolor=color.new(color.green, 90))
if is_dbr_bearish()
label.new(bar_index[1], low[1], "DBR", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small)
// Draw the supply/demand zone as a rectangle at the base candle high and low
box.new(bar_index[1], high[1], bar_index, low[1], border_color=color.green, bgcolor=color.new(color.green, 90))
if is_dbd_bearish()
label.new(bar_index[1], high[1], "DBD", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)
// Draw the supply/demand zone as a rectangle at the base candle high and low
box.new(bar_index[1], high[1], bar_index, low[1], border_color=color.red, bgcolor=color.new(color.red, 90))
if is_rbd_bullish()
label.new(bar_index[1], high[1], "RBD", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)
// Draw the supply/demand zone as a rectangle at the base candle high and low
box.new(bar_index[1], high[1], bar_index, low[1], border_color=color.red, bgcolor=color.new(color.red, 90))