dandy
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: September 29th, 2020

Struggling with 'undeclared identifier issue'

So this script does so far what it should - it plots higher highs as blue bars on the chart:


//@version=4
study("Strat3", overlay=true)


// get user input
rsiLength = input(title="RSI Length", type=input.integer, defval=14)
rsiOB = input(title="RSI OB", type=input.float, defval=70.0)
rsiOS = input(title="RSI OS", type=input.float, defval=30.0)

// get rsi value
rsi = rsi(close, rsiLength)

//detect higher highs and higher lows, or lower lows and lower highs
HH = ((high>=high[1] and low>low[1]) or (high>high[1] and low>=low[1]))
LL = ((high<high[1] and low<=low[1]) or (high<=high[1] and low<low[1]))


//ConsHH/LL input
ConsHH = input(5, title="Consecutive HH's")
ConsLL = input(5, title="Consecutive LL's")


barcolor(HH ? color.blue: na)

So it clearly recognises the declared identifier "HH"

My aim is to have an HH and LL count, so eventually I can put this into a system to go long after 2 HH's for instance.

However when I add the following in my steps to create the HH/LL count:

HH = ((high>=high[1] and low>low[1]) or (high>high[1] and low>=low[1])) ?nz(HH[1])+1:0
LL = ((high<high[1] and low<=low[1]) or (high<=high[1] and low<low[1])) ?nz(LL[1])+1:0
HHCount = HH - valuewhen(HH < HH[1], HH , 1 )
LLCount = LL - valuewhen(LL < LL[1], LL , 1 )


I am getting the "underclared Identifier 'HH' and 'LL' on Lines 16, 17, 18. 19 and even now on line 61 where I set the bar color.

I am most confused and have tried many things - can anyone please give some insight into where I'm going wrong? It would be much appreciated!

Thanks

Dandy

User avatar
Matthew
Site Admin
Site Admin
Posts: 92
Joined: July 1st, 2020
Location: Australia
Contact: Website Facebook Twitter TradingView Profile

Re: Struggling with 'undeclared identifier issue'

Hey Dandy!

Sorry mate, I don't have time to look into this one for you. Hopefully someone else on the forum can help you out but if not check out this article which contains a lot of helpful info on how to deal with that particular error:

https://kodify.net/tradingview/errors/u ... dentifier/

Good luck with your coding & trading and if I get a spare half an hour I'll try and play around with your code but at first glance I'm not sure what's causing that issue.

kmarryat
Pine Script Rookie
Pine Script Rookie
Posts: 20
Joined: December 21st, 2020
Contact: TradingView Profile

Re: Struggling with 'undeclared identifier issue'

I believe your problem is that you are trying to reference the HH and LL values in the same lines that you are defining them. I'm pretty sure you can't do that with version 4. You have to declare it first, then use := to change it's value. Hope this helps.

HH = 0.0
LL = 0.0

HH := ((high>=high[1] and low>low[1]) or (high>high[1] and low>=low[1])) ?nz(HH[1])+1:0
LL := ((high<high[1] and low<=low[1]) or (high<=high[1] and low<low[1])) ?nz(LL[1])+1:0
HHCount = HH - valuewhen(HH < HH[1], HH , 1 )
LLCount = LL - valuewhen(LL < LL[1], LL , 1 )

User avatar
Matthew
Site Admin
Site Admin
Posts: 92
Joined: July 1st, 2020
Location: Australia
Contact: Website Facebook Twitter TradingView Profile

Re: Struggling with 'undeclared identifier issue'

^ absolutely spot on, I didn't notice that you were referencing the same variable on the same line. You definitely can't do that in Pine v4 and that solution above is correct. Thanks kmarryat!

Return to “Pine Script Q&A”