Tick TimeStamp Backtesting Indicator
Tick TimeStamp Backtesting Indicator
10 Apr 2022, 18:17
Have seen all the other posts about this and the recommendation is to use Server.Time to get the tick time when backtesting but this is not accurate and totally fails if the backtest is sped up more than 1x
Is there any way to get the actual tick timestamp when backtesting as is possible when using the indicator live?
Following abbreviated code/approach works live
public class MarketDataSample : Indicator
{
private Ticks ticks;
protected override void Initialize()
{
ticks = MarketData.GetTicks(SymbolName);
ticks.Tick += Event_Tick;
}
public override void Calculate(int index)
{
}
public void Event_Tick(TicksTickEventArgs Args)
{
var tick_LastValue_Time = Args.Ticks.LastTick.Time;
}
}
}
but when backtesting the .LastTick is the tick at the very end of the chart (the bit that exists 'in time' but can't be backtested) and getting the total tick count var total_Ticks = Args.Ticks.Count and using Args.Ticks.Last(total_Ticks).Time or Args.Ticks.Last(0).Time just gets the first and last tick in that unbacktestable series... can't find how to get the actual tick that just occurred in backtesting...
Any ideas/other approaches how could make this work please?
Thanks
Replies
Xammo
11 Apr 2022, 14:13
RE:
Great ok that's good to know and yeh I hadn't tried it in the cBot itself (ran out of steam trying from the indicator and decided to post on here) - will give it a go/wait for 4.2 many thanks
Seemed like it should have been in the Bars. collection which gets triggered in the Calculate method every tick already (IsLastBar) like the Tick.Volume already available ----->
on public override void Calculate(int index)
{
double tick_Volume_LastValue = Bars.TickVolumes.LastValue;
DateTime tick_Time_LastValue = Bars.TickTimes.LastValue; //<-------- would be good
}
@Xammo
amusleh
11 Apr 2022, 12:33
Hi,
We are aware of this issue and it's fixed on cTrader 4.2.
But it works if you use ticks inside cBot itself.
Here is an example:
Result:
@amusleh