BarPeriod

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. 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.

Type:

var

BarOffset

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.

BarZone

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.

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 (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, by skipping bars f.i. outside market hours, or when no price ticks arrive, or until a certain time of the day, or for emulating special bars, such as Range or Renko Bars, without using a bar function. For this, set TimeFrame to 0 for skipping the current bar; count all the skipped bars; and when the event happens, set TimeFrame to the negative number of skipped bars for ending the frame. See remarks and example; see also 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:

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 (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, Bar, BarOffset, LookBack, dayHigh, Date, Weekend, AssetFrame, frameSync, bar

 

► latest version online