Skip to content

Plugin.OnTimer

method · Plugin · cAlgo.API

DesktopCLICloud

Called when the timer interval has elapsed.

Environment behaviour

CLI — not supported. Plugins cannot run in the CLI: ctrader-cli runs cBots only.

Cloud — not supported. Plugins cannot run in the cloud: it runs cBots only.

Definition

protected void OnTimer()
api.OnTimer() -> None

Examples

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();
}
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()