Ernestas
Ernestas

Reputation: 165

Pinescript timeframe since last crossover

I'm quite new to pinescript v5 and can't figure out how to get the timeframe between MA crossovers.

For example, an ma crossover indicates a downtrend, I need the timeframe(candles) since last crossover indicating an uptrend.

Sounds like there should be a simple solution, yet I can't find one.

timeframe between MA crossovers

Upvotes: 0

Views: 1268

Answers (1)

vitruvius
vitruvius

Reputation: 21121

You can use the ta.barssince() function or a simple counter for that.

ta.barssince: Counts the number of bars since the last time the condition was true.

bars_since_ma_crossover = ta.barssince(ta.crossover(ma1, ma2))

Upvotes: 2

Related Questions