I'm running a strategy on a 5 min bars but calculated on each tick with Tick replay enabled.
The results that I get from BackTesting are so wrong. Exits have nothing to do with reality. Despite trades should be filled based on ticks, I get exit fills at the next 5 min bar.
E.g. Image, From Backtest, the 11 October at 11:44.06 in ES. Entry at 3627.50, and exit at 11:45:00 at 3622.50 despite that price never existed at that time (It seems it's taking exits with ticks previous to the entry).
In Market replay, I'd have stopped out at 11:44:33 at 3629.25. This is correct.
Any idea why? How can I change the strategy to have a real exits based on ticks, so have the exit at 11:44:36.
Calculate = Calculate.OnEachTick;
IncludeCommission = true;
RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
IsExitOnSessionCloseStrategy = false;
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Tick, 1);
...........
protected override void OnBarUpdate()
{
if (BarsInProgress != 0) return;
if (CurrentBar < BarsRequiredToTrade) return;
if (_lastBar == CurrentBar) return;
if (Position.MarketPosition == MarketPosition.Flat)
{
var support = _sr.SupportPrice[0];
if (Low[0] <= support && Close[0] >= support + ExtraRetracementTicks * TickSize)
{
if (_sr.SupportTouches[0] >= MinTouches)
{
if (_lastLevel.ApproxCompare(support) != 0)
{
EnterLong(1, 1, "buy");
_lastBar = CurrentBar;
_lastLevel = support;
SetProfitTarget(CalculationMode.Ticks, TakeProfit);
var ticks = (Close[0] - Low[0]) / TickSize;
if (ticks < 4) ticks = 4;
ticks += ExtraSLTicks;
SetStopLoss(CalculationMode.Ticks, ticks);
return;
}

Comment