I have created an indicator in Pine Script which shows CP +/- ATR Zone based on ATR, TR and DATR. But, when I toggle Buy and Sell Zone, it gives an error "mismatch input table, expect input line". I want to show the correct price in the table, but it is not updating correctly. Below is my code, in which I have done Calculation of Buy and Sell Zone. I have used table.clear() and table.new() but still the Table is not updating the values. I need to fix the mismatch input table, expect input line error. Also, I want the table to update correctly and show the correct Buy and Sell Zone values. This Pine Script
//@version=5
indicator("KTP, ATR, TR & DATR Merged", overlay=true)
// === Input Parameters ===
lengthATR = input(14, "ATR Length")
multiplier5 = input(0.05, "ATR 5% Multiplier")
multiplier10 = input(0.10, "ATR 10% Multiplier")
show_buy_zone = input(true, "Show Buy Zone")
show_sell_zone = input(false, "Show Sell Zone")
// === ATR, TR, and DATR Calculation ===
atrValue = ta.atr(lengthATR)
trValue = ta.tr(true)
datrValue = ta.sma(trValue, lengthATR)
// === CP +/- ATR Calculation ===
buy_zone_price_5 = close - (atrValue * multiplier5)
sell_zone_price_5 = close + (atrValue * multiplier5)
buy_zone_price_10 = close - (atrValue * multiplier10)
sell_zone_price_10 = close + (atrValue * multiplier10)
// === Zone Display Logic ===
var table zone_table = table.new(position.top_right, 2, 2, bgcolor=color.black, frame_width=1, frame_color=color.gray)
table.clear(zone_table)
// === Show Buy Zone Only ===
if show_buy_zone and not show_sell_zone
table.cell(zone_table, 0, 0, "Buy Zone 5%:", text_color=color.green)
table.cell(zone_table, 1, 0, str.tostring(buy_zone_price_5, format="#.##"), text_color=color.green)
table.cell(zone_table, 0, 1, "Buy Zone 10%:", text_color=color.green)
table.cell(zone_table, 1, 1, str.tostring(buy_zone_price_10, format="#.##"), text_color=color.green)
// === Show Sell Zone Only ===
else if show_sell_zone and not show_buy_zone
table.cell(zone_table, 0, 0, "Sell Zone 5%:", text_color=color.red)
table.cell(zone_table, 1, 0, str.tostring(sell_zone_price_5, format="#.##"), text_color=color.red)
table.cell(zone_table, 0, 1, "Sell Zone 10%:", text_color=color.red)
table.cell(zone_table, 1, 1, str.tostring(sell_zone_price_10, format="#.##"), text_color=color.red)
// === Show Both Zones ===
else if show_buy_zone and show_sell_zone
table.cell(zone_table, 0, 0, "Buy Zone 5%:", text_color=color.green)
table.cell(zone_table, 1, 0, str.tostring(buy_zone_price_5, format="#.##"), text_color=color.green)
table.cell(zone_table, 0, 1, "Sell Zone 5%:", text_color=color.red)
table.cell(zone_table, 1, 1, str.tostring(sell_zone_price_5, format="#.##"), text_color=color.red)
// === Version Details ===
var string version_details = "Version: 1.0 | Date: 21-Mar-2025 | Updated by ChatGPT"
label.new(bar_index, high, version_details, color=color.blue, text_size=size.small)