I'm using a multi-time frame script that has 10sec bars as my primary dataseries, and ticks as my secondary. I'm calculating OnEachTick. It's proving troublesome to get live results to match backtesting (I know it'll never be perfect but I know I'm quite far off currently). I don't use Bid/Ask data so I haven't developed OnMarketData for TickReplay. I 'think' I need to introduce a 1-tick delay to my backtest entries and exits, and I'm hoping to check my understanding on a few things to understand if I'm approaching the solution correctly please...
In realtime, I always have an extra primary bar because there is always the current bar being built, and BarsInProgess 0 fires with each tick being processed (e.g. every tick received will prompt a BarsInProgress 0 OnBarUpdate, as it updates the currently being built bar). To reference the last fully built bar in reatime, I need to use Close[1], whereas in historical mode there is no bar currently being built so I need to reference Close[0]. In summary, when using OnEachTick & a secondary tick series, I need to treat realtime = Close[1] & Historical = Close[0] as equivalents? So when doing calculations and tick counting in realtime, I need to calculate on Close[1] and log my tick count series as [1], and use the equivalent [0] in historical. Is this understanding correct please?
If I have understood this correctly, in theory I will always be one tick delayed in realtime vs historical because historical already 'knows' the bar ended when it did and doesn't need to wait an extra tick to know this, whereas realtime needs to see an extra tick before it realizes the old bar has now closed. Is this understanding correct please?
Getting to my question. In historical, is there a way of artifically creating this one tick delay so my backtest matches how realtime would behave? I'm thinking of something along the lines of waiting until the first tick of a new 10sec bar comes through, and then calling my primary series from within my secondary series, e.g.:
if (historical == true) { if (BarsInProgress == 1 && ThisIsTheFirstTickSinceThePrimaryBarClosed == true) { if (Closes[0][0] > Opens[0][0]) { //do something } } } if (historical == false) { if (BarsInProgress == 0) { if (Close[1] > Open[1] { //do something } } }
Many thanks in advance
ChainsawDR
Comment