The duration of one bar in minutes, with a range from 100 ms (0.100/60.) up to 1 day (24*60); default = 60. This is the basic time frame in the script. It determines the width of a bar in the chart, and the frequency of the run function that is called after every bar. If not explicitly set up in the script, it is determined by the [Period] slider. Price-movement bars (see bar function) have no fixed bar period; in that case BarPeriod should be set to the average duration of a bar.




Bar start time offset in minutes; must be smaller than BarPeriod. Bars and frames normally start at a date/time boundary; f.i. 60-minute bars start at every full hour, and daily bars start at every midnight (except for weekends). This can be changed with BarOffset. For daily bars, BarOffset determines the UTC minute into the day when the candle opens, and can be used to shift the bar begin to a certain local or global time. BarOffset is automatically set up by NumSampleCycles by dividing a bar into equal time intervals and decreasing the offset by one interval per cycle; on the last cycle, BarOffset is 0.


Time zone that determines the close time of daily bars. Can be set to UTC for UTC time (default), ET for New York, WET for London, CET for Frankfurt, AEST for Sydney, JST for Tokyo, or any number giving the zone offset in hours to UTC. Daylight saving time is used except for UTC and JST. Please see the remarks about StartWeek and EndWeek, which are in UTC; adapt them to the local market hours if necessary.


Time frame in bars (default = 1) used for all subsequent price, time, series, advise, and trade calls. This variable can be set within a strategy for using multiple time frames (see remarks below). For instance, with a bar period of 5 minutes (BarPeriod = 5) and a time frame of 12 bars (TimeFrame = 12), series and trade signals use a one hour time frame (5*12 = 60 minutes).
  TimeFrame can also be used for synchronizing time frames to external events - f.i. for skipping bars outside market hours or when no price ticks arrive, for trading dependent on the time of the day, or for emulating price-movement bars such as Range or Renko Bars. For this, set TimeFrame to 0 during the frame, count the skipped bars, and set TimeFrame to the negative number of skipped bars for ending the frame (see remarks and example; see also AssetFrame).


Time frame offset in bars (default = 0 = no offset) used for all subsequent price, time, series, and trade calls; must be smaller than TimeFrame. When fixed time frames are used, this variable determines the bar number within a time frame when series are shifted and trades are executed. This variable allows to generate trade signals at different times dependent on the asset.





#define H24 (1440/BarPeriod)
#define H4 (240/BarPeriod)
#define H1 (60/BarPeriod)
BarPeriod = 60; // 1 hour (60 minutes) bars
// create a 4-hour price series
TimeFrame = H4;
vars PriceH4 = series(price());

// create a 24-hour price series
TimeFrame = H24;
vars PriceH24 = series(price());

// skip bars outside market hours
static int SkippedBars = 0;
if(between(hour(),MARKETCLOSE,MARKETOPEN-1)) {
TimeFrame = 0;
SkippedBars--; // count negative number of bars outside market hours
} else if(TimeFrame == 0)
TimeFrame = SkippedBars;
SkippedBars = 0;
} else
TimeFrame = 1;
vars PriceInMarketHours = series(price()); // create a midnight-aligned daily price series static int BarsPerDay = 0; if(hour(0) < hour(1)) { // day change TimeFrame = BarsPerDay; // end the frame BarsPerDay = 0; } else { TimeFrame = 0; // inside the frame BarsPerDay--; // count negative number of bars per day } vars PriceD1 = series(price()); // alternative: a midnight-aligned price series using frameSync() StartWeek = 10000; TimeFrame = frameSync(H24); vars PriceD1 = series(price()); // back to 1-hour time frames TimeFrame = 1; ...

See also:

Bars and Candles, Bar, BarOffset, LookBack, dayHigh, Date, Weekend, AssetFrame, frameSync, bar


► latest version online