Counters increase indefinitely. How to reset?

572 Views Asked by At

I have the below code. However when plotted the counters increase indefinitely. I want to count only once per candle. How would I reset the count each candle?

//@version=4
study("bull/bear count")
var Bullcor = 0
var Bearcor = 0

currency1 = input("EURUSD", title="Positive Correlation 1")

security1 = security(currency1,"15",close)

ema50s1 =ema(security1,50)

ema200s1 =ema(security1,200)

if ema50s1>ema200s1
    Bullcor := Bullcor + 1

if ema50s1<ema200s1
    Bearcor := Bearcor + 1

// debug:    
plot(Bullcor, color = color.green)
plot(Bearcor, color = color.red)
1

There are 1 best solutions below

0
On BEST ANSWER

Remove the var keyword or change it to int

int Bullcor = 0
int Bearcor = 0

This way the script will assign 0 to Bullcor and Bearcor variables on every new candle and after that will check the if statements.