Remove label from zones like RBR, DBR and extend zone box to current price and sometimes…
- User
Remove label from zones like RBR, DBR and extend zone box to current price and sometimes distal line is placed on the lowest point of RBR Formation Bottom but we want to place distal line on lowest Point of Base Candles in RBR Formation: //@version=5 indicator("Advanced Demand Zone Detector with Proximal Line Adjustments", overlay=true)
// User Inputs base_candles = input.int(2, "Number of Base Candles", minval=1, maxval=6) small_range_multiplier = input.float(0.5, "Base Candle 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)
// Arrays to store zones and associated data var box[] demand_zones = array.new() var line[] distal_lines = array.new() var line[] proximal_lines = array.new() var label[] zone_labels = array.new() var float[] zone_lows = array.new_float() var float[] zone_highs = array.new_float() var float[] proximal_prices = array.new_float() var int[] zone_types = array.new_int() // 1 for RBR, 2 for DBR
// Function to check for violation f_check_violation(index) => zone_low = array.get(zone_lows, index) zone_high = array.get(zone_highs, index) proximal_price = array.get(proximal_prices, index) // For Demand Zones, violation occurs when price closes below the zone_low if close < zone_low // Remove box, lines, and label box.delete(array.get(demand_zones, index)) line.delete(array.get(distal_lines, index)) line.delete(array.get(proximal_lines, index)) label.delete(array.get(zone_labels, index)) // Remove from arrays array.remove(demand_zones, index) array.remove(distal_lines, index) array.remove(proximal_lines, index) array.remove(zone_labels, index) array.remove(zone_lows, index) array.remove(zone_highs, index) array.remove(proximal_prices, index) array.remove(zone_types, index)
// RBR Detection
// Check if initial rally candle before base candles is bullish rally1 = close[base_candles + 1] > open[base_candles + 1]
// Initialize variables base = true total_base_size = 0.0 float proximal_price = na // Explicitly declare the variable type
// Check base candles and find proximal price for i = 0 to base_candles - 1 idx = base_candles - i base_candle_size = math.abs(close[idx] - open[idx]) base := base and base_candle_size < avg_range[idx] * small_range_multiplier total_base_size += base_candle_size // Calculate candle body top body_top = math.max(open[idx], close[idx]) proximal_price := na(proximal_price) ? body_top : math.max(proximal_price, body_top)
avg_base_size = total_base_size / base_candles
// Legout candle is current candle legout_candle_size = math.abs(close - open)
// Check if legout candle is bullish and its size is more than double the avg base candle size rally2 = (close > open) and (legout_candle_size > 2 * avg_base_size)
// Ensure overall upward movement overall_up = close > close[base_candles + 1]
// Determine if pattern is RBR isRBR = rally1 and base and rally2 and overall_up
- Assistant