---
id: "M:cAlgo.API.ChartArea.XToBarIndex(System.Double)"
kind: "method"
type: "T:cAlgo.API.ChartArea"
url: "https://help.ctrader.com/ctrader-algo/references/Chart/ChartArea/XToBarIndex/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# ChartArea.XToBarIndex

Member of [ChartArea](https://help.ctrader.com/ctrader-algo/references/Chart/ChartArea/index.md).

## XToBarIndex(double x)

Converts X coordinate to bar index.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: Always returns 0; no conversion is done.
- Cloud: Always returns 0; no conversion is done.

C#:

```csharp
double XToBarIndex(double x)
```

Python:

```python
chartArea.XToBarIndex(x: float) -> float
```

### Parameters

- `x` (`double`, Python `float`): X coordinate

### Returns

`double` — Bar Index

### Examples

C#:

```csharp
var barIndex = Chart.XToBarIndex(Chart.Width / 2);
Print("Bar index at the chart center: {0}", barIndex);
```

Python:

```python
barIndex = api.Chart.XToBarIndex(api.Chart.Width / 2)
api.Print(f"Bar index at the chart center: {barIndex}")
```

