Discrepancy between counted ticks and tick volume
11 Sep 2019, 14:46
i noticed by running this simple algo that the number of ticks processed during a simgle bar timespan in a backtest is not equal to the number of ticks shown in the bar's tick volume:
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TickVerifier : Robot
{
private int ticks = 0;
protected override void OnTick()
{
ticks++;
}
protected override void OnBar()
{
Print(MarketSeries.TickVolume.Last(1) + " vs " + ticks + " counted.");
ticks = 0;
}
}
}
I would like to know if an explaination of this phenomena is possible, whether it is normal or caused but data inconsistency from the broker.
Thanks in advance
-C
Replies
PanagiotisCharalampous
12 Sep 2019, 11:25
Hi all,
By design OnTick() will trigger only once if both bid and ask change. However TickVolume will add to the volume two ticks for both bid and ask price changes. A more accurate way to calculate and compare tick volume is the following
private int TickVolume;
private decimal LastBid;
private decimal LastAsk;
protected override void OnTick()
{
var bid = (decimal)Symbol.Bid;
var ask = (decimal)Symbol.Ask;
if (bid != LastBid)
TickVolume++;
if (ask != LastAsk)
TickVolume++;
LastBid = bid;
LastAsk = ask;
}
protected override void OnBar()
{
Print(MarketSeries.TickVolume.Last(1) + " vs " + TickVolume + " counted.");
TickVolume = 0;
}
Best Regards,
Panagiotis
@PanagiotisCharalampous

eivaremir
11 Sep 2019, 17:57 ( Updated at: 21 Dec 2023, 09:21 )
I noticed this a day I backtested a bot which is tick sensitive. At every tick, desitions based on global P/L are made. For example: close trade if there's a 0.50 profit and open another again... or vice versa if its a loss then close and open another again. If there's a movement which changes my P/L to .40 then .55 then .45 there would exist a closed trade in profit and a trade opened. but if the data doesn't inlude the 2nd tick then the trade will still be open (.4->.45) the close trigger will never be executed. That's why ticks does affect the performance of the equity curve.
So i backtested it and i had an unusual result for just a period of time... This was somepoint between June 2015 and August 2015
So I did a similar procedure Cysecbin did... I exported the difference between the Ticks processed by the bot vs the MarketSeries.TickVolume to a .txt and i got interesting results...
Statistically the results are these, seems like all the time ticks processed are only the 80%-60% of the real ticks existed. The only moment the majority of real ticks were processed (90%-100%) happened during these 2 months at 2015, which reproduced almost 20k trades resulting in a huge profit for my algorithm, affecting the results dramatically...
I would like to know how to respond to this situation...
@eivaremir