Reputation: 65
I am trying to add Bollinger Band and Triple EMA Crossover together but encountering the following message - "Add to Chart operation failed, reason: line 16: Could not find function or function reference 'study'."
My code is as follows -
//@version=5
indicator(shorttitle="BB", title="Bollinger Bands", overlay=true, timeframe="", timeframe_gaps=true)
length = input.int(20, minval=1)
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
//@version=3
study(title="TEMA Crossover", shorttitle="TEMAC", overlay=true)
len1 = input(10, minval=1, title="Length 1")
len2 = input(20, minval=2, title="Length 2")
ema1 = ema(close, len1)
ema11 = ema(ema1, len1)
ema111 = ema(ema11, len1)
tema1 = 3 * (ema1 - ema11) + ema111
ema2 = ema(close, len2)
ema22 = ema(ema2, len2)
ema222 = ema(ema22, len2)
tema2 = 3 * (ema2 - ema22) + ema222
plot(tema1, color=black, transp=20)
plot(tema2, color=maroon, transp=20)
Please help me to resolve this issue.
Thanks & regards.
Upvotes: 0
Views: 193
Reputation: 21342
You cannot have two study/indicator
calls in one script. That is the script identifier and can only be one.
Your TEMA code is also copied from version 3
, which is not compatible with version 5
. So, it needs to be upgraded too.
//@version=5
indicator(shorttitle="BB", title="Bollinger Bands", overlay=true, timeframe="", timeframe_gaps=true)
length = input.int(20, minval=1)
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
// TEMA
len1 = input.int(10, minval=1, title="Length 1")
len2 = input.int(20, minval=2, title="Length 2")
ema1 = ta.ema(close, len1)
ema11 = ta.ema(ema1, len1)
ema111 = ta.ema(ema11, len1)
tema1 = 3 * (ema1 - ema11) + ema111
ema2 = ta.ema(close, len2)
ema22 = ta.ema(ema2, len2)
ema222 = ta.ema(ema22, len2)
tema2 = 3 * (ema2 - ema22) + ema222
color_tema1 = color.new(color.black, 20)
color_tema2 = color.new(color.maroon, 20)
plot(tema1, color=color_tema1)
plot(tema2, color=color_tema2)
Upvotes: 1