BarPeriod

The duration of one bar in minutes (default = 60). The theoretical minimum bar period is one second (1./60) for normal scripts, and 1 ms (0.001/60) for HFT simulation. Typical price curve inefficiencies disappear on low time frames, so don't go below 60 for indicators, filters, or analysis functions. Use 1440 for daily and 10080 for weekly bar periods. 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.

Type:

var

BarOffset

Bar start/end time offset in minutes; 0 or a positive number smaller than BarPeriod (default = 940 with daily bars, otherwise 0). 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 when BarOffset is 0. For daily bars, use BarOffset shift the bar begin to the desired trading time of the day; the 940 default sets it to 15:40 in the bar time zone. BarOffset is also automatically set by NumSampleCycles for dividing a bar into equal time intervals and decreasing the offset by one interval per cycle; on the last cycle, BarOffset is 0.  

TimeFrame

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.

FrameOffset

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.

Type:

int

Remarks:

TimeFrame vs. BarPeriod:

Examples:

#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(!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