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

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

# Robot.OnStart

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

## OnStart()

Called when cBot is being started. Override this method to initialize cBot, create nested indicators, etc.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
protected internal void OnStart()
```

Python:

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

### Examples

C#:

```csharp
private SimpleMovingAverage _sma;

protected override void OnStart()
{
    _sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, 20);
    Print("cBot started on {0} {1}", SymbolName, TimeFrame);
}
```

Python:

```python
def on_start(self):
    self.sma = api.Indicators.SimpleMovingAverage(api.Bars.ClosePrices, 20)
    api.Print(f"cBot started on {api.SymbolName} {api.TimeFrame}")
```

