I want to plot the label with the following pine script that I can record it when I export the data and make an alert when the label comes out:
if array.size(zigzagpivots) > i_loopback * 2 + 2
lastConfirmedPivot = array.get(zigzagpivots, 1)
lastConfirmedPivotBar = array.get(zigzagpivotbars, 1)
lastConfirmedPivotDir = array.get(zigzagpivotdirs, 1)
if ta.change(lastConfirmedPivot)
for i = 1 to i_loopback - 1 by 1
iDir = array.get(zigzagpivotdirs, i) % 2
iDir := iDir % 2 == 0 ? iDir / 2 : iDir
for j = i + 2 to i_loopback + 1 by 2
iPivotPattern = iDir * array.get(zigzagpivots, i) > iDir * array.get(zigzagpivots, j) ? iDir * 2 : iDir
pattern := pattern + str.tostring(iDir)
pattern
lastIndex := array.indexof(patternArray, pattern)
if lastIndex != -1
randomColor = f_random_color(70)
lastBarIndex = array.get(patternBarArray, lastIndex)
lastOccurance = time[bar_index - lastBarIndex]
lastTime = str.tostring(year(lastOccurance), '0000') + '/' + str.tostring(month(lastOccurance), '00') + '/' + str.tostring(dayofmonth(lastOccurance), '00') + (timeframe.isintraday ? '-' + str.tostring(hour(lastOccurance), '00') + ':' + str.tostring(minute(lastOccurance), '00') + ':' + str.tostring(second(lastOccurance), '00') : '')
yloc = lastConfirmedPivotDir > 0 ? yloc.abovebar : yloc.belowbar
style = lastConfirmedPivotDir > 0 ? label.style_triangledown : label.style_triangleup
label.new(lastConfirmedPivotBar, close, text='', color=randomColor, style=style, tooltip='⬅ ' + lastTime, yloc=yloc)
plot(lastConfirmedPivotBar)
array.unshift(patternArray, pattern)
array.unshift(patternBarArray, bar_index)
However, it comes out with the an error:
Cannot use 'plot' in local scope
How to fix the problem?