Why won't this code run in Pine Script 4? "Undeclared identifier"
Solution 1
v4 RefMan is here: https://www.tradingview.com/pine-script-reference/v4/
v4 UserMan is here: https://www.tradingview.com/pine-script-docs/en/v4/index.html
Since compiler is returning an error on line 4 which uses input()
, makes sense to look up the function in refman, where you will find that the proper argument to type=
parameter for what you want is now input.resolution
. Being unable to initialize variable dRange
because of the error, the compiler also gives an error on that variable. Same goes with adRange
, which you've fixed.
Solution 2
I solved it, but still don't know what "undeclared identifiers" were. I assume it's just Pine's way of saying that dRange
violated the new rules with its variable resolution
, and that adRange
was creating problems with the un-used tickerid
, which has been replaced by syminfo.tickerid
in PineScript 4.
//@version=4
study(title="Average Daily Range", shorttitle="ADR", overlay=false)
adRange = security(syminfo.tickerid, "D", rma(tr, 5))
plot(adRange, title="ADR", color=#000000, transp=0)
alexeix
Updated on June 09, 2022Comments
-
alexeix about 2 years
Resources are still Pine Script 3 heavy, so I think I'm mixing something up:
I tried to create an Average Daily Range indicator, which is basically the ATR that takes a "D" input no matter what the time frame of the current chart is. My code works perfectly fine on Pine Script 3, but Pine Script 4 throws out the following errors:
line 4: Undeclared identifier `resolution`; line 6: Undeclared identifier `tickerid`; line 6: Undeclared identifier `dRange`; line 8: Undeclared identifier `adRange`
The docs indicate
resolution
is still aninput()
argument, and I'm not sure why anything else is called "undeclared".My full code is:
//@version=4 study(title="Average Daily Range", shorttitle="ADR", overlay=false) dRange = input(defval="D", title="Daily Range", type=resolution) adRange = security(tickerid, dRange, rma(tr, 5)) plot(adRange, title = "ADR", color=#000000, transp=0)
What are these "Undeclared identifiers"? And what must I do differently in Pine Script 4 so that I'm getting the same result?
Thank you.