Reputation: 59
I'm looking at the Pine version 3 migration guide and there's an example showing a custom function and using security() to call that function. https://www.tradingview.com/wiki/Pine_Version_3_Migration_Guide
Now I tried to change my custom function in order to return two values instead of one, but for some reason it doesn't work anymore. The error is on line 10 ("[t,i] = ...") and says: variableType.itemType is not a function.
My code below, can anyone advise what the issue is please?
//@version=3
study("My Script")
calcS() =>
s = 0.0
j = 0.0
s := close + 1
j := close + 2
[s, j]
[t, i] = security(tickerid, '120', calcS())
plot(t, color=red, transp=0)
plot(i, color=blue, transp=0)
Upvotes: 0
Views: 2726
Reputation: 8779
UPDATE
Starting with Pine v4 you can use functions returning tuples with security()
:
//@version=4
study("", "", true)
f() => [open, high]
[o, h] = security(syminfo.tickerid, "D", f())
plot(o)
plot(h)
Upvotes: 0
Reputation: 442
It's a known problem. You can't return tuple from security. It's in our plans to fix this bug.
Now you may use the following workaround:
//@version=3
study("My Script")
calcS() =>
s = 0.0
j = 0.0
s := close + 1
j := close + 2
[s, j]
calcSs() =>
[s, j] = calcS()
s
calcSj() =>
[s, j] = calcS()
j
t = security(tickerid, '120', calcSs())
i = security(tickerid, '120', calcSj())
plot(t, color=red, transp=0)
plot(i, color=blue, transp=0)
Upvotes: 2