Tick Volume discrepancy?
Created at 05 Jul 2013, 11:27
FL
Tick Volume discrepancy?
05 Jul 2013, 11:27
Hi,
I have noticed that OnTick() gets called more often than the number of times indicated by the tickVolume.
The output of the following Robot code illustrates this.
Robot Code:
using System; using System.IO; using cAlgo.API; namespace cAlgo.Robots { [Robot] public class Test : Robot { StreamWriter logWriter; double actualTicks; protected override void OnStart() { // Create a new log file on the User's Desktop. logWriter =
File.CreateText(
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Symbol.Code + "_" + Server.Time.ToString("ddMMyyyy_HHmm") + ".csv")); logWriter.AutoFlush = true; logWriter.WriteLine("Open Time, Open, High, Low, Closed, Bid, Ask, Tick Volume, Actual Ticks"); actualTicks = 0; } protected override void OnTick() { // Start counting ticks at the start of a bar. if (actualTicks == 0 && MarketSeries.TickVolume.LastValue == 1) actualTicks = 1; // Wait until the start of a bar. if (actualTicks == 0) return; // Reset countedTicks at the start of a bar otherwise increment. actualTicks = (MarketSeries.TickVolume.LastValue == 1) ? 1 : actualTicks + 1; //Write data to file, indicating Tick Volume discrepancies with a *. logWriter.WriteLine(MarketSeries.OpenTime.LastValue.ToString("dd/MM/yyyy, HH:mm:ss") + ", " + MarketSeries.Open.LastValue.ToString("F0" + Symbol.Digits) + ", " + MarketSeries.High.LastValue.ToString("F0" + Symbol.Digits) + ", " + MarketSeries.Low.LastValue.ToString("F0" + Symbol.Digits) + ", " + MarketSeries.Close.LastValue.ToString("F0" + Symbol.Digits) + ", " + Symbol.Bid.ToString("F0" + Symbol.Digits) + ", " + Symbol.Ask.ToString("F0" + Symbol.Digits) + ", " + MarketSeries.TickVolume.LastValue + ", " + actualTicks + (actualTicks != MarketSeries.TickVolume.LastValue ? "*" : "")); } protected override void OnStop() { // Close logfile. logWriter.Close(); } } }
Robot Output:
Open Time, Open, High, Low, Closed, Bid, Ask, Tick Volume, Actual Ticks 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28875, 1.28875, 1.28875, 1.28876, 1, 1 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28874, 1.28874, 1.28874, 1.28876, 2, 2 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28871, 1.28871, 1.28871, 1.28872, 3, 3 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28870, 1.28870, 1.28870, 1.28870, 4, 4 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28870, 1.28871, 1.28871, 1.28871, 5, 5 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28870, 1.28870, 1.28870, 1.28870, 6, 6 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28870, 1.28870, 1.28870, 1.28871, 6, 7* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28870, 1.28870, 1.28870, 1.28870, 6, 8* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28868, 1.28868, 1.28868, 1.28868, 7, 9* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28866, 1.28866, 1.28866, 1.28868, 8, 10* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28866, 1.28866, 1.28866, 1.28869, 8, 11* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28866, 1.28867, 1.28867, 1.28870, 9, 12* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28866, 1.28867, 1.28867, 1.28868, 9, 13* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28866, 1.28866, 1.28866, 1.28868, 10, 14* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28865, 1.28865, 1.28865, 1.28868, 11, 15* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28865, 1.28866, 1.28866, 1.28868, 12, 16* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28865, 1.28867, 1.28867, 1.28868, 13, 17* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28865, 1.28866, 1.28866, 1.28868, 14, 18* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28865, 1.28866, 1.28866, 1.28866, 14, 19* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28864, 1.28864, 1.28864, 1.28866, 15, 20* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28864, 1.28864, 1.28864, 1.28865, 15, 21* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28863, 1.28863, 1.28863, 1.28865, 16, 22* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28863, 1.28863, 1.28863, 1.28866, 16, 23* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28863, 1.28864, 1.28864, 1.28866, 17, 24* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28863, 1.28864, 1.28864, 1.28865, 17, 25* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28863, 1.28863, 1.28863, 1.28865, 18, 26* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28862, 1.28862, 1.28862, 1.28865, 19, 27* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28862, 1.28862, 1.28862, 1.28864, 19, 28* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28862, 1.28862, 1.28862, 1.28862, 19, 29* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28861, 1.28861, 1.28861, 20, 30* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28865, 1.28865, 1.28866, 21, 31* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28864, 1.28864, 1.28866, 22, 32* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28866, 1.28866, 1.28866, 23, 33* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28864, 1.28864, 1.28866, 24, 34* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28865, 1.28865, 1.28866, 25, 35* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28864, 1.28864, 1.28866, 26, 36* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28866, 1.28866, 1.28866, 27, 37* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28867, 1.28867, 1.28869, 28, 38* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28872, 1.28872, 1.28872, 29, 39* 05/07/2013, 08:05:00, 1.28875, 1.28875, 1.28861, 1.28875, 1.28875, 1.28875, 30, 40* 05/07/2013, 08:05:00, 1.28875, 1.28876, 1.28861, 1.28876, 1.28876, 1.28876, 31, 41* 05/07/2013, 08:05:00, 1.28875, 1.28876, 1.28861, 1.28876, 1.28876, 1.28877, 31, 42* 05/07/2013, 08:05:00, 1.28875, 1.28876, 1.28861, 1.28876, 1.28876, 1.28878, 31, 43* 05/07/2013, 08:05:00, 1.28875, 1.28877, 1.28861, 1.28877, 1.28877, 1.28879, 32, 44* 05/07/2013, 08:05:00, 1.28875, 1.28879, 1.28861, 1.28879, 1.28879, 1.28880, 33, 45* 05/07/2013, 08:05:00, 1.28875, 1.28879, 1.28861, 1.28878, 1.28878, 1.28880, 34, 46* 05/07/2013, 08:05:00, 1.28875, 1.28879, 1.28861, 1.28876, 1.28876, 1.28878, 35, 47* 05/07/2013, 08:05:00, 1.28875, 1.28879, 1.28861, 1.28876, 1.28876, 1.28877, 35, 48* 05/07/2013, 08:05:00, 1.28875, 1.28879, 1.28861, 1.28875, 1.28875, 1.28877, 36, 49* 05/07/2013, 08:05:00, 1.28875, 1.28879, 1.28861, 1.28875, 1.28875, 1.28878, 36, 50* 05/07/2013, 08:05:00, 1.28875, 1.28879, 1.28861, 1.28876, 1.28876, 1.28878, 37, 51* 05/07/2013, 08:05:00, 1.28875, 1.28879, 1.28861, 1.28878, 1.28878, 1.28878, 38, 52* 05/07/2013, 08:05:00, 1.28875, 1.28881, 1.28861, 1.28881, 1.28881, 1.28881, 39, 53* 05/07/2013, 08:05:00, 1.28875, 1.28882, 1.28861, 1.28882, 1.28882, 1.28883, 40, 54* 05/07/2013, 08:05:00, 1.28875, 1.28882, 1.28861, 1.28882, 1.28882, 1.28882, 40, 55* 05/07/2013, 08:05:00, 1.28875, 1.28882, 1.28861, 1.28881, 1.28881, 1.28882, 41, 56* 05/07/2013, 08:05:00, 1.28875, 1.28882, 1.28861, 1.28881, 1.28881, 1.28883, 41, 57* 05/07/2013, 08:05:00, 1.28875, 1.28883, 1.28861, 1.28883, 1.28883, 1.28883, 42, 58* 05/07/2013, 08:05:00, 1.28875, 1.28886, 1.28861, 1.28886, 1.28886, 1.28886, 43, 59* 05/07/2013, 08:05:00, 1.28875, 1.28886, 1.28861, 1.28884, 1.28884, 1.28884, 44, 60* 05/07/2013, 08:05:00, 1.28875, 1.28886, 1.28861, 1.28884, 1.28884, 1.28886, 44, 61* 05/07/2013, 08:05:00, 1.28875, 1.28886, 1.28861, 1.28884, 1.28884, 1.28884, 44, 62* 05/07/2013, 08:05:00, 1.28875, 1.28886, 1.28861, 1.28883, 1.28883, 1.28884, 45, 63* 05/07/2013, 08:05:00, 1.28875, 1.28886, 1.28861, 1.28883, 1.28883, 1.28886, 45, 64* 05/07/2013, 08:05:00, 1.28875, 1.28886, 1.28861, 1.28884, 1.28884, 1.28886, 46, 65* 05/07/2013, 08:05:00, 1.28875, 1.28886, 1.28861, 1.28884, 1.28884, 1.28884, 46, 66* 05/07/2013, 08:06:00, 1.28883, 1.28883, 1.28883, 1.28883, 1.28883, 1.28884, 1, 1 05/07/2013, 08:06:00, 1.28883, 1.28883, 1.28883, 1.28883, 1.28883, 1.28886, 1, 1 05/07/2013, 08:06:00, 1.28883, 1.28884, 1.28883, 1.28884, 1.28884, 1.28886, 2, 2 05/07/2013, 08:06:00, 1.28883, 1.28884, 1.28883, 1.28884, 1.28884, 1.28887, 2, 3* 05/07/2013, 08:06:00, 1.28883, 1.28886, 1.28883, 1.28886, 1.28886, 1.28888, 3, 4*
The discrepancies are shown in the lines ending with a '*'. In this case OnTick() was called 66 times and the Tick Volume is only 46 for the 1-minute bar. The output also shows several lines with the same Tick Volume value indicating an unnecessary (?) OnTick() calls. The next bar is showing a similar problem. Please advise.
Thanks,
FlatLander
cAlgo_Fanatic
05 Jul 2013, 16:16
Hello,
The tick volume is increased only when the Bid price changes, so it will not be the same as the number of times the OnTick event is being called which occurs when either the Bid or the Ask price change.
@cAlgo_Fanatic