I am using Pine Script which is used in tradingview.com.

My question is: Is it possible to update a variable depending on a condition?

Here is a variable called 'index' which increase everytime the 'buycondition' is False. The variable 'index' returns to 0 everytime when the 'buycondition' becomes True.

```
index = 0
if (buycondition == 0) // 0 for False
    index += 1        
else:
    index = 0

```

The goal is to know the candlestick distance between the last 'buycondition' and the last 'sellcondition'