Multiple Timers / OnTimer events

Created at 28 May 2015, 17:40
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
JE

JeremyG

Joined 26.03.2015

Multiple Timers / OnTimer events
28 May 2015, 17:40


Hi,

 

Does any know if it's possible to use multiple Timers and OnTimer() events?

For example, I want one timer to count one hour periods and then fire an event, and another timer counting minutes periods and firing an event etc.

 

Muchas gracias!


@JeremyG
Replies

Spotware
12 Jun 2015, 12:51

Dear Trader,

Currently there is only one Timer object in cAlgo.API. We will consider providing users the ability to use multiple timers.


@Spotware

Tj11
22 Mar 2020, 10:32

You could use the construction :

public TimeSpan timePassed;

 

protected override void OnTimer()
        {
            timePassed = timePassed + Timer.Interval;

            //example seconds

            if (timePassed.Seconds > 10)
            {
            }
        }


@Tj11

firemyst
08 Apr 2020, 17:25

RE:

Tj11 said:

You could use the construction :

public TimeSpan timePassed;

 

protected override void OnTimer()
        {
            timePassed = timePassed + Timer.Interval;

            //example seconds

            if (timePassed.Seconds > 10)
            {
            }
        }

Good start of a work around. However, the biggest drawback is the timer event would have to be set to go off at the smallest common interval.

For instance, if you want an event to happen every 5 seconds and 30 seconds, you have to set the timer event to either 1 or 5 seconds; if you set it at 2, 3, 4, or something else, one of those 5/30 second events will be 'late'.

Similarly, if you want an event to happen every 30 seconds and another at 4 minutes (240 seconds), you have to set the timer event to occur at 1, 5, 10, 15, or 30 second intervals.

The next thing is change the ">" to ">="

:-)


@firemyst