dcmb
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: December 7th, 2023

labels in sequence

Hi,

i wanted to add labels to my chart in sequence, e.g. label1, label2, label3 based on different criteria.

I coded them using nested ifs but doesn't seemed to work. my codes are as below but label3 does not appear on the chart.

if I removed label2, label1 and label3 will appear correctly.

Code: Select all

if ta.crossover(fastSMA, slowSMA)
    labelLong1 := label.new(bar_index, high, size=size.tiny, style=label.style_label_down, color = color.rgb(175, 168, 76), text = '1', textcolor = color.rgb(1,0,5))
    
    LongclosedAbove9SMA =  close > fastSMA
    if LongclosedAbove9SMA
        labelLong2 := label.new(bar_index, high, size=size.tiny, style=label.style_label_down, color = color.rgb(175, 168, 76), text = '2', textcolor = color.rgb(1,0,5))
     
        LongLowBelow9SMA =  low < fastSMA
        if LongLowBelow9SMA
            labelLong3 := label.new(bar_index, high, size=size.tiny, style=label.style_label_down, color = color.rgb(175, 168, 76), text = '3', textcolor = color.rgb(1,0,5))
how can i make the labels appeared in sequence?

Return to “Pine Script Q&A”