OnTimer() Sync Issue

Created at 23 Oct 2019, 16:43
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!
SA

sascha.dawe

Joined 11.02.2019

OnTimer() Sync Issue
23 Oct 2019, 16:43


Hi,

I am in the process of trying to copy tick data into an array per interval (In this case, every second), but am having trouble syncing the timer with actual time.

The bot is meant to start collecting tick volume at the beginning of the new bar, and compare values at end of the minute. But it seems unreliable in terms of starting on time. Sometimes starting a few seconds after new bar event. Other times skipping seconds at random times. 

What could be causing this issue. Is there an extra step I should be doing to sync correctly?

Note on below code: period is equal to 60.

Thanks.

Sascha

 

 protected override void OnStart()
        {
            pauseBot=true;
            Timer.Start(1);
         }
 protected override void OnBar()
 {
            pauseBot = false;
 }
 
 protected override void OnTimer()
        {
            if (pauseBot)
            {
                return;
            }
            for (int i = period; i >= 1; i--)
            {
                volArray[i] = volArray[i - 1];
            }
            volArray[0] = MarketSeries.TickVolume.LastValue;
            Print("Current bar volume ", volArray[0]);
            Print("Bar (-1) corresponding volume ", volArray[period]);
        }

 


@sascha.dawe
Replies

srubtsov
25 Oct 2019, 16:18

Hi,

I don't understand exactly what do you want. But I think a time-based algorithm, not a good idea. For example, you don't have a guarantee about `OnBar` calls exactly at the start of the minute. m1 `OnBar` calls after the first bid changing in the new minute.


@srubtsov

sascha.dawe
25 Oct 2019, 22:43

Thanks for your reply, I am trying to collect tick volume data for one minute, then comparing the corresponding time tune When it changes to new bar,. The idea is to see if the volume has changed compared to the previous time period. This would be compared on a per second basis. I have discovered the exact problem you have stated about new bar not starting on time. Also, lastvalue tick volume can also can also run into new bar. I have compensated for this. Is there a general approach you could recommend instead?
@sascha.dawe

srubtsov
28 Oct 2019, 10:24

lastvalue tick volume can also can also run into new bar.

Could you describe it with more details? Maybe with logs.


@srubtsov

sascha.dawe
28 Oct 2019, 11:42

Actually, I think I have it sorted, thanks.

After your last post regarding the weakness of using a time based method, I changed my approach.

Now I just record tick volume as it happens on tick and date stamp it at that point in time. Then, insert this data into a dictionary object, using datetime as key (checking 

for duplicates before adding) I can then call previous time periods by date and match up corresponding times, syncing via new bar event.  This is still somewhat time based, but seems to be quite effective, versus just storing tick volume in an array via timer.


@sascha.dawe