Timer
Summary
Schedules execution of virtual OnTimer method with specified interval.
Signature
| public abstract interface Timer
|
Namespace
cAlgo.API
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 | using cAlgo.API;
using System;
namespace cAlgo.Robots
{
// This sample cBot shows how to use the API Timer, this timer works both on live and back test
// The timer is available for both cBots and indicators
// Every cBot/indicator can have one single timer
// You can also use the .NET timers if you want to but those will not work properly on back test
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TimerSample : Robot
{
protected override void OnStart()
{
// You can start the cBot timer by calling Timer.Start method, for interval you can pass a time span or seconds
Timer.Start(TimeSpan.FromSeconds(1));
// You can also use the TimerTick event instead of OnTimer method
Timer.TimerTick += Timer_TimerTick;
// To stop the timer you can call Timer.Stop method anywhere on your cBot/indicator
Timer.Stop();
}
private void Timer_TimerTick()
{
// Put your logic for timer elapsed event here
}
protected override void OnTimer()
{
// Put your logic for timer elapsed event here
}
}
}
|
Methods
Start (2)
Start (1 of 2)
Summary
Starts the Timer
Signature
| public abstract void Start(TimeSpan interval)
|
Parameters
Name | Type | Description |
interval | TimeSpan | Interval as a TimeSpan |
Return Value
void
Start (2 of 2)
Summary
Starts the Timer
Signature
| public abstract void Start(int intervalInSeconds)
|
Parameters
Name | Type | Description |
intervalInSeconds | int | Interval in seconds |
Return Value
void
Stop
Summary
Stops the Timer
Signature
| public abstract void Stop()
|
Return Value
void
Properties
Interval
Summary
Gets the interval of timer. Returns -1 millisecond if the timer is stopped
Signature
| public abstract TimeSpan Interval {get;}
|
Return Value
TimeSpan
Events
TimerTick
Summary
Occurs when the interval elapses
Signature
| public abstract event Action TimerTick;
|
Examples
| protected override void OnStart()
{
Timer.TimerTick += OnTimerTick
Timer.Start(1);//start timer with 1 second interval
}
private void OnTimerTick()
{
ChartObjects.DrawText("time", Time.ToString("HH:mm:ss"), StaticPosition.TopLeft);
}
|