I have a strategy that uses moving averages derived from a daily strategy, and looks at bars from an "Add"ed 1 minute series (on the same instrument) to make trading decisions and enter trades.
When I execute trades from within the 1 minute bars, I use EnterLong or EnterShort with 1 as the BarsInProgress index.
The problem is that during backtesting, the trades are not being executed until the next daily bar, rather than at the start of the next 1 minute bar as desired.
I've looked at the SampleIntrabarBacktest strategty, and modifed it to do what I'm doing:
// if (BarsInProgress == 0)
if (BarsInProgress == 1)
{
// When the fast EMA crosses above the slow EMA, enter long on the secondary (1min) bar series
if (CrossAbove(EMA(Fast), EMA(Slow), 1))
{
/* The entry condition is triggered on the primary bar series, but the order is sent and filled on the
secondary bar series. The way the bar series is determined is by the first parameter: 0 = primary bars,
1 = secondary bars, 2 = tertiary bars, etc. */
EnterLong(1, 1, "Long: 1min");
Print("Long at " + Time);
}
// When the fast EMA crosses below the slow EMA, enter short on the secondary (1min) bar series
else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
{
/* The entry condition is triggered on the primary bar series, but the order is sent and filled on the
secondary bar series. The way the bar series is determined is by the first parameter: 0 = primary bars,
1 = secondary bars, 2 = tertiary bars, etc. */
EnterShort(1, 1, "Short: 1min");
Print("Short at " + Time);
}
}
// When the OnBarUpdate() is called from the secondary bar series, do nothing.
else
{
return;
}
The debug printouts show that the trades are being entered on 1 minute intervals, but the trade log shows that the trades are executed at the start of the next primary bar (which I set to 5 minutes for this test).
Help - how can I get my trades to execute at the start of the next 1 minute bar instead of at the start of the next primary bar ?
Bob A.
Comment