2
votes

I m coding in Pine Script and I am trying to increase the variable "count" by 1 when a logical test is confirmed "close >= open", so I try to use the following code:

var count = 0
if close >= open
    count := count + 1
plot(count)

When I try to save it I get the following error msg:

"no viable alternative at input 'count'"

If I try to remove the "var" in front of the count, always 0 is plotted in the chart.

Any ideas where the problem is? Thx

1

1 Answers

0
votes

You are certainly using the v2 version of Pinescript, make sure that you are using //@version=4.

You can also use the following form:

count = cum(close >= open ? 1 : 0)