Create a TradingView Indicator that can detect Demand Zone that has DBR and RBR formation
- User
Create a TradingView Indicator that can detect Demand Zone that has DBR and RBR formation
- Assistant
Create a TradingView Indicator that can detect Demand Zone that has DBR and RBR formation
Certainly! Below is a TradingView Indicator written in Pine Script (version 5) that detects Demand Zones with Drop-Base-Rally (DBR) and Rally-Base-Rally (RBR) formations. This script identifies these patterns and plots the Demand Zones on the chart.
//@version=5
indicator("Demand Zone Detector with DBR and RBR formations", overlay=true)
// User Inputs
base_candles = input.int(2, "Number of Base Candles", minval=1, maxval=3)
small_range_multiplier = input.float(0.5, "Small Range Multiplier", minval=0.1, step=0.1)
atr_length = input.int(14, "ATR Length", minval=1)
// Calculations
avg_range = ta.sma(ta.tr, atr_length)
// RBR Detection
rally1 = close[base_candles + 1] > open[base_candles + 1]
base = true
if base_candles >= 1
base := base and abs(close[base_candles] - open[base_candles]) < avg_range[base_candles] * small_range_multiplier
if base_candles >= 2
base := base and abs(close[base_candles - 1] - open[base_candles - 1]) < avg_range[base_candles - 1] * small_range_multiplier
if base_candles == 3
base := base and abs(close[base_candles - 2] - open[base_candles - 2]) < avg_range[base_candles - 2] * small_range_multiplier
rally2 = close > open
overall_up = close > close[base_candles + 1]
isRBR = rally1 and base and rally2 and overall_up
// DBR Detection
drop1 = close[base_candles + 1] < open[base_candles + 1]
base_d = true
if base_candles >= 1
base_d := base_d and abs(close[base_candles] - open[base_candles]) < avg_range[base_candles] * small_range_multiplier
if base_candles >= 2
base_d := base_d and abs(close[base_candles - 1] - open[base_candles - 1]) < avg_range[base_candles - 1] * small_range_multiplier
if base_candles == 3
base_d := base_d and abs(close[base_candles - 2] - open[base_candles - 2]) < avg_range[base_candles - 2] * small_range_multiplier
rally = close > open
overall_up_d = close > close[base_candles + 1]
isDBR = drop1 and base_d and rally and overall_up_d
// Plot Demand Zones
var box demand_zone = na
if isRBR or isDBR
// Determine the base zone
zone_high = max(open[base_candles], close[base_candles])
zone_low = min(open[base_candles], close[base_candles])
if base_candles >= 2
zone_high := max(zone_high, max(open[base_candles - 1], close[base_candles - 1]))
zone_low := min(zone_low, min(open[base_candles - 1], close[base_candles - 1]))
if base_candles == 3
zone_high := max(zone_high, max(open[base_candles - 2], close[base_candles - 2]))
zone_low := min(zone_low, min(open[base_candles - 2], close[base_candles - 2]))
// Draw a rectangle to represent the demand zone
zone_start = bar_index[base_candles]
zone_end = bar_index
color_zone = isRBR ? color.new(color.green, 80) : color.new(color.blue, 80)
if na(demand_zone)
demand_zone := box.new(left=zone_start, top=zone_high, right=zone_end, bottom=zone_low, border_color=color_zone, bgcolor=color_zone)
else
box.set_left(demand_zone, zone_start)
box.set_right(demand_zone, zone_end)
box.set_top(demand_zone, zone_high)
box.set_bottom(demand_zone, zone_low)
box.set_bgcolor(demand_zone, color_zone)
else
if not na(demand_zone)
box.delete(demand_zone)
demand_zone := na
// Plot labels
if isRBR
label.new(bar_index, high, "RBR Detected", style=label.style_label_down, color=color.green)
if isDBR
label.new(bar_index, high, "DBR Detected", style=label.style_label_down, color=color.blue)
Average Range Calculation: The script calculates the average true range (ATR) over a specified period (atr_length) to determine what constitutes a "small" candle range in the context of the base candles.
Pattern Detection:
base_candles) have a small range (less than a multiple of the ATR).Demand Zone Plotting:
box) on the chart to highlight this zone.Labels: The script places a label on the chart at the point where an RBR or DBR pattern is detected for easy identification.
base_candles): You can adjust the number of candles that define the base of the pattern (1 to 3).small_range_multiplier): This determines how small the base candles should be relative to the ATR. A smaller multiplier means stricter criteria for what constitutes a small range.atr_length): The period over which the Average True Range is calculated.Adding the Indicator:
Interpreting the Signals:
Making Trading Decisions:
Limitations:
Further Enhancements:
Feel free to customize the parameters and expand upon the script to better suit your trading needs. Happy trading!
Not yet included in a published release.