Multiple Time Frames in TickZOOM
TickZoom calls the different types of bar data "bar intervals" instead of time frames since this covers all other non-time based bar types like volume, range, as well as time frames like 1 day and 4 hour.
Your strategies always get the following builtin intervals at a minimum. 1 Year, 1 Month, 1 Week, 1 Session, 1 Day, 1 Tick plus the GUI choice as a default. The ticks will either be real ticks or simulated ticks if you're using bar data for input.
The GUI choice is considered the "default" interval. You can override (aka hardcode) this interval in your strategy if you choose. But that never affects the GUI so you can still chart in using any interval. Your strategy results get overlayed onto the chart, in that case.
But the default interval differs from the rest because you will always get its bar data on the Bars property. And it fires the OnIntervalClose() and OnIntervalOpen() events without any arguments. So it can be accessed, like so:
Bars.High[0];
Any other intervals must be access by the Data property. Like so:
Data.Hour1.High[0];
These intervals fire the OnIntervalOpen(Interval interval) and OnIntervalClose(Interval interval) methods.
You can request additional intervals in your strategy or indicator constructor:
RequestUpdate(Intervals.Minute15);
Many common time frames are defined for convenience on the Intervals class. If you need a custom one, you can either add it to the project--we welcome contributors--or specify it this way:
RequestUpdate(Intervals.Define(BarUnit.Minute, 15)); RequestUpdate(Intervals.Define(BarUnit.Volume, 100));
There are two ways you can access these custom bars:
1. You can get them via the Data.Get() method anywhere you need them. This method works especially if you want the bar size to be a variable. It's hard coded here to be a 100 Volume bar as an example.
Data.Get(Intervals.Define(BarUnit.Volume, 100)).High[0];
2. Or you can assign a variable on your OnInitialize() method for greater convenience, like this:
Interval intervalMinute15 = Intervals.Define(BarUnit.Minute,15);
Bars minute15;
public void OnInitialize() {
minute15 = Data.Get(intervalMinute15);
}
Then, for any of the events in your strategy you can simply refer to your bars like this:
minute15.High[2]; minute15.Close[0];
Note that these bars get updated on every tick. So you can access them in the OnProcessTick() event also will real time information.
Also the bars fire the OnIntervalOpen(Interval interval) and OnIntervalClose(Interval interval) methods which you can catch if you desire:
public bool OnIntervalClose( Interval interval) {
if( interval.Equals(intervalMinute15) {
Process15MinuteClose(); // <-- Your method to handle the event.
}
return true;
}
Comment by junkone on Sun 17 May 2009 09:18:44 AM CDT
i want to access multitimeframe data status during the bar. for eg. i want to get the cci(14) value on 1 minute bars and 5 minute bars. the way i understand it, i can access bar data only on onIntevalClose or onIntervalOpen.
however i want to access the different timeframes during the OnProcessTick(Tick tick) as i will evaluate the cci value related to 1 minute or 5 minute bars as i get tick by tick data.
difference=cci[0]-cci[1]; enterOrder=difference>15;
i dont want to wait for the 1 minute or 5 minute Bar to close before i enter the order. so how do i do it.
Comment by waynewalter on Sun 17 May 2009 08:22:08 PM CDT
You can access bar data in any of the events including OnInitialize() except in OnInitialize() they're all empty. So use them in OnProcessTick() as well.
Just do exactly what you said in OnProcessTick(). Did you try yet? It works fine.
Well, maybe one detail that you're missing. Currently TickZoom requires you to "create" your indicators in OnInitialize() and then you can use them anywhere else.
So define 2 fields, create the indicator in OnInitialize(), and then use them wherever else:
CCI longCCI;
CCI shortCCI;
public override void OnInitialize() {
RequestUpdate( Intervals.Minute5);
shortCCI = Formula.CCI( Minutes.Close, 14);
longCCI = Formula.CCI( Minute5.Close, 14);
}
Then use shortCCI[0] and longCCI[0] anywhere, including OnProcessTick().
