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

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

# Plugin.OnTimer

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

## OnTimer()

Called when the timer interval has elapsed.

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

- CLI: Plugins cannot run in the CLI: ctrader-cli runs cBots only.
- Cloud: Plugins cannot run in the cloud: it runs cBots only.

C#:

```csharp
protected void OnTimer()
```

Python:

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

### Examples

C#:

```csharp
private int _ticks;

protected override void OnStart()
{
    Timer.Start(1);
}

protected override void OnTimer()
{
    _ticks++;
    Print("Timer tick {0} at {1}", _ticks, Server.Time);
    if (_ticks == 10)
        Timer.Stop();
}
```

Python:

```python
def on_start(self):
    self.ticks = 0
    api.Timer.Start(1)

def on_timer(self):
    self.ticks += 1
    api.Print(f"Timer tick {self.ticks} at {api.Server.Time}")
    if self.ticks == 10:
        api.Timer.Stop()
```

