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

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

# Robot.OnStop

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

## OnStop()

Called when cBot is stopped.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
protected internal void OnStop()
```

Python:

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

### Examples

C#:

```csharp
protected override void OnStop()
{
    foreach (var position in Positions.FindAll("myLabel"))
        ClosePosition(position);
    Print("cBot stopped, positions closed");
}
```

Python:

```python
def on_stop(self):
    for position in api.Positions.FindAll("myLabel"):
        api.ClosePosition(position)
    api.Print("cBot stopped, positions closed")
```

