OnTimer() Sync Issue
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]); }
Replies
sascha.dawe
25 Oct 2019, 22:43
@sascha.dawe
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
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