> For the complete documentation index, see [llms.txt](https://fto-2.gitbook.io/fto-indicators-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fto-2.gitbook.io/fto-indicators-docs/api-reference/current-symbol/bar-indexing.md).

# Bar indexing

## Purpose

Use the same reverse index convention when reading prices and writing indicator buffers.

## Workflow

1. Treat index `0` as the current, most recent bar on the right edge of the chart.
2. Add `1` to step one bar back into history (the last fully formed bar).
3. In `OnCalculate(index)`, read older bars with `index + 1` and store results at `index`.
4. Call [Bars](/fto-indicators-docs/api-reference/current-symbol/bars.md) before reading beyond loaded history.

## Example

```typescript
public override OnCalculate(index: number): void {
    if (index + 1 >= this.api.Bars()) {
        return
    }

    const change = this.api.Close(index) - this.api.Close(index + 1)
    this.ChangeBuffer.setValue(index, change)
}
```

## Related API

* [Close](/fto-indicators-docs/api-reference/current-symbol/close.md)
* [OnCalculate](/fto-indicators-docs/api-reference/lifecycle/on-calculate.md)
* [Market data](/fto-indicators-docs/api-reference/current-symbol.md)
