I notice a strange occurrence back-testing a multitimeframe system.
I am running the backtest on 1440min bars (i.e. 1 day) on ES 09-14
And I've added a 1min time period within code, (which I place trades off)
When I print out the Time[0] for first bar of session, I've been getting unusal values.
I should see 23:01 (because in UK when the US mini S&P opens it is 23:00)
But sometimes I also see 00:01 as the first bar, AND THEN an additional 'firstbarofsession' for the same session, but with the correct 23:01.
THERE CAN ONLY BE ONE FIRST BAR OF SESSION RIGHT? Why are there sometimes two occasions in a day that set the FirstBarOfSession flag to true?
Also sometimes days are missed out e.g. Sunday and Friday. I understand Friday as markets shut.. but why is Sunday sometimes missed out and sometimes it is there. Please see the code then a copy of my output:
Ps I'm using latest version of NT 7...25 and use Rithmic connection but it uses NinjaTrader historical servers for data
Day = Monday
1st bar time = 01/02/2010 00:01:00
Day = Monday
1st bar time = 01/02/2010 23:01:00 Why are there two First bars for this session?
Day = Tuesday
1st bar time = 02/02/2010 23:01:00
Day = Wednesday
1st bar time = 03/02/2010 23:01:00
Day = Thursday
1st bar time = 04/02/2010 23:01:00
Day = Monday
1st bar time = 08/02/2010 00:01:00
Day = Monday
1st bar time = 08/02/2010 23:01:00
and again why are there two first bars for this session?
Day = Tuesday
1st bar time = 09/02/2010 23:01:00
Day = Wednesday
1st bar time = 10/02/2010 23:01:00
Day = Thursday
1st bar time = 11/02/2010 23:01:00
Day = Monday
1st bar time = 15/02/2010 00:01:00
Day = Tuesday
1st bar time = 16/02/2010 00:01:00
and again there are two First bars for this session?
Day = Tuesday
1st bar time = 16/02/2010 23:01:00
Day = Wednesday
1st bar time = 17/02/2010 23:01:00
Day = Thursday
1st bar time = 18/02/2010 23:01:00
Day = Monday
1st bar time = 22/02/2010 00:01:00
Day = Monday
1st bar time = 22/02/2010 23:02:00
Ps where is Sunday or Friday? Sunday should appear
And the guilty code is here:
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
// **************************************
// **** NOTE BACKTEST on 1440 min bars ****
//*****************************************
Print("NOTE: Remember to use 1440 min bars for backtest..");
Add(PeriodType.Minute, 1); // Add intraday timeframe..
ClearOutputWindow();
CalculateOnBarClose = true;
ExitOnClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (BarsInProgress == 1 // Intraday..
&& Bars.FirstBarOfSession == true)
{
Print("Day = " + Time[0].DayOfWeek.ToString());
Print("1st bar time = " + Time[0]);
Print("");
}
...}
Any help would be much appreciated
Thanks guys!
Comment