CountedBars
Returns the number of bars that have already been calculated in previous calls.
Syntax
Counted_bars(): numberParameters
This method does not take any parameters.
Return Value
Returns a number representing the count of bars that have already been calculated.
Description
The Counted_bars method returns the number of bars that have already been processed in previous calls to the indicator's calculation function. This is useful for optimization, as it allows the indicator to only calculate values for new bars rather than recalculating all bars.
Example
// Get the number of already calculated bars
const counted = this.api.Counted_bars()
// Use it to optimize calculations
const total = this.api.Bars()
const limit = counted > 0 ? total - counted : total - 1
// Only calculate for new bars
for (let i = limit; i >= 0; i--) {
// Perform indicator calculations for bar at index i
}Last updated