TimeFrameSet
- switch price arrays to a different time frame

Time Frame functions
(AmiBroker 4.50)


SYNTAX TimeFrameSet( interval)
RETURNS NOTHING
FUNCTION The TimeFrameSet replaces current price/volume arrays: open, high, low, close, volume, openint, avg with time-compressed bars of specified interval once you switched to a different time frame all calculations and built-in indicators operate on selected time frame. To get back to original interval call TimeFrameRestore() function. Before calling TimeFrameSet again in the same formula with different interval you have to restore original time frame first using TimeFrameRestore.

interval defines time frame interval in seconds. So 60 means 1-minute. For the convenience the following interval constants are pre-defined:

  • in1Minute = 60
  • in5Minute = 5 * 60
  • in15Minute = 15 * 60
  • inHourly = 3600
  • inDaily = 24 * 3600
  • inWeekly = 5 * 24 * 3600 + 1 = 432001
  • inMonthly = 25 * 24 * 3600 + 1 = 2160001
  • inQuarterly (new in 5.20)
  • inYearly (new in 5.20)

To get other intervals you can use multiple of pre-defined intervals, for example: ( 3*in1Minute ) gives 3 minute bars. Or you can use 3 * inDaily for 3-day bars.

New in version 4.70 and above: You can also use NEGATIVE values for N-tick charts: -5 fives 5-tick chart. Note that N-tick compression works correct only if you have 1-tick base time interval selected in database settings.

You can also use TimeFrameSet to create N-volume bars as well as Range bars. See TimeFrameMode() function for more details.

VERY IMPORTANT:
inWeekly constant is now 432001 ( 5*inDaily + 1 ) - in previous version it was 432000
inMonthly constant is now 2160001 ( 25*inDaily + 1 ) - in previous version it was 2160000
It is changed because now N-day custom intervals are supported and they will interfere with weekly/monthly.
Note that 5*inDaily is now DIFFERENT than inWeekly. 5*inDaily creates 5-day bars that DO NOT necesarily cover Monday-Friday while inWeekly ALWAYS creates bars that begin on Monday and end on Friday. Also 25*inDaily creates 25-day bars that DO NOT necesarily represent full month, while inMonthly always begins with first day of the month and ends at the last day of the month

Once you switch the time frame using TimeFrameSet , all AFL functions operate on this time frame until you switch back the time frame to original interval using TimeFrameRestore or set to different interval again using TimeFrameSet. It is good idea to ALWAYS call TimeFrameRestore when you are done with processing in other time frames.

When time frame is switched to other than original interval the results of all functions called since TimeFrameSet are time-compressed too. If you want to display them in original time frame you would need to 'expand' them as described later. Variables created and assigned before call to TimeFrameSet() remain in the time frame they were created. This behaviour allows mixing unlimited different time frames in single formula.

Please note that you can only compress data from shorter interval to longer interval. So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, ....N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames.

For more information check: Tutorial: Multiple time frame support in AFL

EXAMPLE TimeFrameSet( in5Minute ); // switch to 5 minute frame

/* MA now operates on 5 minute data, ma5_13 holds time-compressed 13 bar MA of 5min bars */

ma5_13 =
MA( C, 13 );

TimeFrameRestore(); // restore time frame to original

TimeFrameSet( inHourly ); // switch now to hourly

mah_9 =
EMA( C, 9 ); // 9 bar moving average from hourly data

TimeFrameRestore(); // restore time frame to original

Plot( Close, "Price", colorWhite, styleCandle );

// plot expanded average

Plot( TimeFrameExpand( ma5_13, in5Minute), "13 bar moving average from 5 min bars", colorRed );
Plot( TimeFrameExpand( mah_9, inHourly), "9 bar moving average from hourly bars", colorRed );

SEE ALSO TimeFrameRestore() function , TimeFrameExpand() function , TimeFrameGetPrice() function

Comments:

Tomasz Janeczko
tj --at-- amibroker.com
2004-06-03 04:35:37
TimeFrameSet(in15Minute);
MA10_15Min=MA(Close,10);
TimeFrameRestore();

Buy=Cross( MA(Close,5), TimeFrameExpand(MA10_15Min, in15Minute) );

References:

The TimeFrameSet function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.