The duration of one bar in minutes (default = 60). The minimum bar period is one second (1./60) for normal scripts, and 1 ms (0.001/60) for HFT simulation. The maximum bar period is one day (1440). The bar period is the basic time frame in the script. It determines the width of a candle 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 can be determined with the [Period] slider. User-defined 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/end time offset in minutes; 0 or a positive number 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 normally start at UTC midnight. This can be changed with BarOffset. For daily bars, BarOffset can be used to shift the bar begin to a certain number of hours and minutes after midnight. This is normally used to trade at a certain time using daily bars. BarOffset is also 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. By default, BarOffset is 940 with daily bars, and 0 on any smaller bar period. 


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, for skipping bars, for synchronizing time frames to external events, or for for emulating special bars such as Range or Renko Bars. 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).
  For synchronizing time frames to a certain event, time, or date, skip the bars inbetween by setting TimeFrame to 0. Count the skipped bars, and set TimeFrame to the negative number of skipped bars when the event happens. The time frame synchronizing mechanism only affects the shifting of series; price and other functions are unaffected. See remarks and example; see also frameSync and 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.




TimeFrame vs. BarPeriod:


#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 (equivalent to AssetMarket) //////
// equivalent to AssetZone
static int SkippedBars = 0;
if(!market(ET,0)) {
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 daily price series (equivalent to AssetZone) //////// 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, NumBars, SampleOffset, LookBack, dayHigh, Date, BarMode, AssetFrame, frameSync, bar


► latest version online