View Full Version : Mixed time frames
cherriman
03-05-2008, 10:03 AM
Hi,
I want to go long the mini-Dow if the Dow Cash closes down today compared with the previous day. Easy - Closes[1][0] < Closes[1][1]. The mini-Dow is the main instrument in the strategy.
If I base the strategy on YM minute bars and wait for after 16:00 EST, the Dow is as of the previous day since Ninja assumes that is the data I want to look at. Obviously, I can't access Closes[1][-1] as the array will not hold that data.
Would this work if I based the strategy on daily DJIA and Add(ed) 1-minute YM bars or would it look to tomorrow ?
Alternatively, could I cheat and create 1-minute DJIA data which was actually the day close -
20080228 160000;12689.28;12713.99;12463.32;12582.18;3938580
20080229 160000;12579.58;12579.58;12210.3;12266.39;4426730
Thanks,
Eric
NinjaTrader_Ray
03-05-2008, 10:23 AM
Hi Eric,
Be patient with me as I try to understand what you want to do...
- You want to go long as the Cash index close of today is less than yesterday
- You want to check this condition today after 16:00 EST
Is this correct? If yes, what are your session start/end times going to be?
cherriman
03-05-2008, 10:37 AM
Hi Ray,
That was quick !
You have it exactly right; if today's Cash close is below yesterday's, I want to go long the mini-Dow. I want to check this as at the Cash close (i.e. just after 4 o'clock). There are obviously certain other conditions !
I'm not sure what you mean by session start/end times so that is probably a big clue ! The position will be held from 16:00EST until it is either stopped out or hits a profit target - this could be any time throughout the night. Sorry to be a thickie - I hope that answers your question albeit indirectly.
Thanks,
Eric
NinjaTrader_Ray
03-05-2008, 10:58 AM
Thanks.
Assuming DOW Mini 1 Minute is the primary series and the Daily series is added in Initialize() can you clarify why this would not work:
if (BarsInProgress == 0)
{
if (Closes[1][0] < Closes[1][1] && ToTime(Time[0]) > 160000)
EnterLong();
}
cherriman
03-05-2008, 11:10 AM
Ray, I haven't tried your code - mine was within OnBarUpdate() - would that make a difference ?
The condition I had was
if ((Closes[1][0] < Closes[1][1]) && (ToTime(Time[0]) > ToTime(16, 00, 0)) && (ToTime(Time[0]) < ToTime(16, 10, 0))).
When I do a debug PrintWithTimeStamp, I get
03/01/2008 16:01:00 Pos Flat Dow cl 13043.96 prev 13264.82
13043.96 is the closing price of the 2nd of January, not the 3rd.
Thanks,
Eric
NinjaTrader_Ray
03-05-2008, 11:18 AM
My code is for OnBarUpdate()
Not sure I follow...
If you do this:
if (BarsInProgress == 0)
Print(Time[0].ToString() + " " + Closes[1][0])
I would expect that you get the close price of daily bars of the time stamp you printed out. Is this not the case?
cherriman
03-06-2008, 07:00 AM
Hi Ray,
Tried driving this from both daily and minute perspective - I suspect that Close[0] for daily is updated at midnight ?
Here it the output from the debug code running the strategy as of 21st Feb 2008 -
29/02/2008 16:01:00 Pos Flat Dow cl 12582.18 prev 12694.28
This is the actual data
20080227;12683.54;12815.59;12527.64;12694.28;39047 00
20080228;12689.28;12713.99;12463.32;12582.18;39385 80
20080229;12579.58;12579.58;12210.3;12266.39;442673 0
As you can see, on the 29th, Ninja assumes day 0 to be yesterday even after 16:00 EST.
I've attached my zipped strategy; I would be grateful if you could help.
Thanks,
Eric
NinjaTrader_Ray
03-06-2008, 07:49 AM
Thanks. This is a limitation of NT 6.5 right now. Could you try running the strategy on a daily chart with the secondary series being the 1 minute.
Then in OnBarUpdate() just only process events for the 1 minute.
if (BarsInProgress == 1)
// Process logic
Is the daily bar now pointing to the correct day?
cherriman
03-06-2008, 09:40 AM
Ray,
I don't know if I'm doing something wrong but NT is evaluating the YM price in Close[x] using the code you suggested !
I'm running the strategy against ^DJIA.
Close[x] points to YM
Closes[x][y] points to YM !
Eric
NinjaTrader_Ray
03-06-2008, 09:54 AM
Right.
Should be:
Close[x]
Closes[y][x]
cherriman
03-06-2008, 10:33 AM
Ray,
That refers to data one bar further back so I'm afraid we're going the wrong way !
By the way, I had assumed that Close[0] would refer to Closes[0][0] - is that incorrect ?
Thanks,
Eric
NinjaTrader_Ray
03-06-2008, 10:52 AM
To be clear:
- Apply strategy on daily chart
- Strategy has a minute series added via Add() in Initialize()
if (!Historical && BarsInProgress == 1)
Print(Times[0][0].ToString() + " " + Closes[0][0]);
cherriman
03-06-2008, 12:08 PM
If that should be within OnBarUpdate() it produces no output at all.
NinjaTrader_Ray
03-06-2008, 12:47 PM
That would be the case if you were backtesting...
I ran a few tests here and I don't think this is the route we should go down. We have internal limitations (which we will change later this year) in when the close of a daily bar is recognized from an intraday time frame.
What you can do is use the GetSessionBar() method which will create a virtual session bar based on your intraday data.
http://www.ninjatrader-support.com/HelpGuideV6/GetSessionBar.html
cherriman
03-07-2008, 10:21 AM
Ray,
As far as I can tell from the tests I've run, the close of the daily bar doesn't occur until midnight - 8 hours after I want to test the strategy.
Can I cheat by setting up a set of minute data for the Dow cash which is just the close - e.g.
20080228 160000;12689.28;12713.99;12463.32;12582.18;3938580
20080229 160000;12579.58;12579.58;12210.3;12266.39;4426730
Would that work do you think ?
Eric
NinjaTrader_Ray
03-07-2008, 10:24 AM
Have you tried what I posted in my last post?
cherriman
03-07-2008, 10:46 AM
Yes, from the tests I did, it occurred at midnight. Subsequent tests of GetSessionBar also refer to the YM
Run without time constraint -
28/02/2008 00:00:00 session close is: 12582.18 time 28/02/2008 00:00:00
28/02/2008 00:01:00 session close is: 12526 time 28/02/2008 00:00:00
Run with time constraint of after 16:00 and less than 16:03, I get
28/02/2008 16:01:00 session close is: 12526 time 28/02/2008 00:00:00
28/02/2008 16:02:00 session close is: 12526 time 28/02/2008 00:00:00
NinjaTrader_Ray
03-07-2008, 12:08 PM
You will need to play around more. It works as expected indpendant of session settings.
If you create a strategy with only the following code in OnBarUpdate() on one series you will see proof in the Output window.
if (Bars.GetSessionBar(1) != null)
Print(Time[0].ToString() + " " + Bars.GetSessionBar(1).Time + " " + Bars.GetSessionBar(1).Close);
cherriman
03-07-2008, 12:44 PM
Ray,
Your code is for yesterday's (1) data. It doesn't update until midnight. It may work as expected but is not doing what is needed.
NinjaTrader_Ray
03-07-2008, 12:57 PM
If today you run this code, it will return the close price from yesterday calculated from the intraday data.
scjohn
03-09-2008, 11:35 AM
Having some what of a similar problem but I am using Daily (primary) and weekly (secondary) data. Using Print() statements I see:
2/29/2008 12:0:00AM[0]
2/29/2008 12:00:00AM[1]
3/3/2008 12:00:00AM[0]
3/4/2008 12:00:00AM[0]
3/5/2008 12:00:00AM[0]
3/6/2008 12:00:00AM[0]
This is running the Strategy Analyzer on Sunday, March 9th. As you can see, there is no daily entry 3/7/2208 or a weekly entry for 3/7/2008. Looks like it will not consider Friday to be complete until Monday's data has been added.
I have played around with the session parameters and that has not gotten NT to consider Friday to be complete. I double checked the chart and the chart is showing a daily bar for 03/7/2008.
Is there something I'm missing or is this the way NT works?
Thanks
NinjaTrader_Josh
03-09-2008, 03:15 PM
When CalculateOnBarClose is set to true (which is the setting for backtesting) it will not include the final bar because it does not know that it has "closed" yet. This is the way NT works with historical data. In real-time you can set CalculateOnBarClose to false and you will get prints on the final bar.
cherriman
03-10-2008, 06:26 AM
Ray,
I set the daily data up as 1 minute at 4 pm (160000). I then accessed the data as minute data and NT obliged. Obviously not the correct solution but it will do for the time being.
e.g.
20080228 160000;12689.28;12713.99;12463.32;12582.18;3938580
20080229 160000;12579.58;12579.58;12210.3;12266.39;4426730
Eric
NinjaTrader_Ray
03-10-2008, 07:03 AM
Excellent :)