---
id: "M:cAlgo.API.Robot.OnBar"
kind: "method"
type: "T:cAlgo.API.Robot"
url: "https://help.ctrader.com/ctrader-algo/references/General/Robot/OnBar/"
---

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

# Robot.OnBar

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

## OnBar()

Called on each incoming Bar.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
protected internal void OnBar()
```

Python:

```python
api.OnBar() -> None
```

### Examples

C#:

```csharp
protected override void OnBar()
{
    Print("New bar opened at {0}, open price {1}", Bars.LastBar.OpenTime, Bars.LastBar.Open);
}
```

Python:

```python
def on_bar(self):
    api.Print(f"New bar opened at {api.Bars.LastBar.OpenTime}, open price {api.Bars.LastBar.Open}")
```

