rassom
rassom

Reputation: 2966

Plot name / label in TradingView pine script

How can I give a plot a name/label? (ses red box in screenshot) code

study(title="Average True Range Channels", shorttitle="ATRC", overlay=true)

slowEMAdays = input(22, minval=1, title="Days for EMA", type=integer)
slowEMA = (ema(close, slowEMAdays))
atrBandDays = input(13, minval=1, title="Days for ATR", type=integer)
atrBand = atr(atrBandDays)
atrPlus1 = slowEMA + atrBand
atrPlus2 = slowEMA + atrBand*2
atrPlus3 = slowEMA + atrBand*3
atrMinus1 = slowEMA - atrBand
atrMinus2 = slowEMA - atrBand*2
atrMinus3 = slowEMA - atrBand*3
plot(slowEMA, color=black, linewidth=2)
plot(atrPlus1, color=green)
plot(atrPlus2, color=orange)
plot(atrPlus3, color=red)
plot(atrMinus1, color=green)
plot(atrMinus2, color=orange)
plot(atrMinus3, color=red)

I want to add an alert to some of the 6 plots but when adding an alert I can only see 6 plots with the same name ("plot") so I cannot easily distinguish them from one another :)

Best, Rasmus

Upvotes: 1

Views: 4539

Answers (1)

Bjorn Mistiaen
Bjorn Mistiaen

Reputation: 6905

Converted to v4 and labeled the plots.

//@version=4
study(title="Average True Range Channels", shorttitle="ATRC", overlay=true)

slowEMAdays = input(22, "Days for EMA", type=input.integer, minval=1)
atrBandDays = input(13, "Days for ATR", type=input.integer, minval=1)

slowEMA = ema(close, slowEMAdays)
atrBand = atr(atrBandDays)

atrPlus1    = slowEMA + atrBand
atrPlus2    = slowEMA + atrBand * 2
atrPlus3    = slowEMA + atrBand * 3

atrMinus1   = slowEMA - atrBand
atrMinus2   = slowEMA - atrBand * 2
atrMinus3   = slowEMA - atrBand * 3

plot(slowEMA,   "slowEMA",   color=color.black, linewidth=2)

plot(atrPlus1,  "atrPlus1",  color=color.green)
plot(atrPlus2,  "atrPlus2",  color=color.orange)
plot(atrPlus3,  "atrPlus3",  color=color.red)

plot(atrMinus1, "atrMinus1", color=color.green)
plot(atrMinus2, "atrMinus2", color=color.orange)
plot(atrMinus3, "atrMinus3", color=color.red)

Upvotes: 2

Related Questions