Page 1 of 1

Struggling with 'undeclared identifier issue'

Posted: Sun Dec 06, 2020 1:59 am
by dandy
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

Re: Struggling with 'undeclared identifier issue'

Posted: Thu Dec 10, 2020 4:08 am
by Matthew
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.

Re: Struggling with 'undeclared identifier issue'

Posted: Mon Dec 21, 2020 10:39 pm
by kmarryat
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 )

Re: Struggling with 'undeclared identifier issue'

Posted: Fri Jan 15, 2021 1:22 am
by Matthew
^ 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!