pine-scriptpine-script-v5

Creating a supply and demand EMA cloud on trading view. I keep having issues with "Undeclared identifier 'label'"


I'm having issues with supply and demand zone labels.

// === ENTRY SIGNAL LOGIC ===
bullish = close > open and close > emaFast
bearish = close < open and close < emaFast

inDemandZone = false
inSupplyZone = false

// Check if we're inside any demand zone
for i = 0 to array.size(demandBoxes) - 1
    boxDemand = array.get(demandBoxes, i)
    boxLow = box.get_bottom(boxDemand)
    boxHigh = box.get_top(boxDemand)
    if low <= boxHigh and low >= boxLow
        inDemandZone := true

// Check if we're inside any supply zone
for i = 0 to array.size(supplyBoxes) - 1
    boxSupply = array.get(supplyBoxes, i)
    boxLow = box.get_bottom(boxSupply)
    boxHigh = box.get_top(boxSupply)
    if high >= boxLow and high <= boxHigh
        inSupplyZone := true

// Draw labels (ensuring no conflict with variable naming)
if inDemandZone and emaFast > emaSlow and bullish and showEntrySignals
    label.new(bar_index, low, "Long", style=label.style_label_up, color=color.green, textcolor=color.white)

if inSupplyZone and emaFast < emaSlow and bearish and showEntrySignals
    label.new(bar_index, high, "Short", style=label.style_labeldown, color=color.red, textcolor=color.white)

Here's the code that keeps having errors

label.new(bar_index, high, "Short", style=label.style_labeldown, color=color.red, textcolor=color.white)

I've tried adding to define labels and that creates new errors and doesn't solve the original problem. Thanks


Solution

  • You have a typo in the style argument of the second label.new(). The correct one is label.style_label_down with a _ between label and down.

    label.new(bar_index, high, "Short", style=label.style_label_down, color=color.red, textcolor=color.white)
    

    Always pay attention to the formatting. Built-in variables will have a different red-ish color. If it is not highlighted, something must be wrong with it.