This is my Pinescript code.
//@version=5
indicator("Strategy", overlay=false)
var count = 0
count := nz(count[1],0)
counter() =>
count := close > close[1] ? count + 1 : count
counter()
plot(count)
Here I am facing an issue in my counter function. I am getting an error in the count inside my counter function. Cannot modify global variable 'count' in function; error displaying in Pinescript compiler. I tried with Var also. still facing the same issue. Please help me to resolve this.
The
countvariable should be defined inside of the function. Also, thecountvariable will not be available outside of the function.The following will work: