1. 首页
  2. BarStatus

BarStatus

BarStatus (Reserved Word)

Description

Used to determine whether the current tick is the opening or closing tick of a bar, or whether it is a tick ‘inside the bar.’

This reserved word will return one of four possible values:

2 = the closing tick of a bar
1 = a tick within a bar
0 = the opening tick of a bar (relevant only for strategies using Open Next Bar order actions)
-1 = an error occurred while executing the reserved word

BarStatus always returns ‘0’ when used in Strategies with ‘open next bar’ type terminology. On non ‘open next bar’ type strategies it will never return ‘0’.

BarStatus is unique, in that it can reference non-existent datastreams without generating a run-time error. i.e. if you apply code with BarStatus(2) to a chart with only one datastream it will return a ‘-1’, but will not generate a run-time error. This is an extremely useful feature, and is discussed further below.

Usage

value1 = BarStatus(DataNum);

where DataNum is a numeric expression representing the data stream that is being evaluated. 1 refers to Data1, 2 to Data2 and so on. DataNum can be between 1 and 50, inclusive.

Examples

Example 1: To perform an operation on the closing tick of every bar:

if BarStatus( 1 ) = 2 then begin
	{Your Operation Here};
end;

Example 2: When using IntrabarOrderGeneration (IOG) you can perform an operation on the first tick of a bar:

[IntrabarOrderGeneration = True]

Vars:	IntrabarPersist FirstTickOfBar(false);

if FirstTickOfBar then begin
	{Your Operation Here};
end;

//Run this at very end of code
FirstTickOfBar = BarStatus(1) = 2;

Example3: This code can be used to determine how many datastreams are currently present on the chart.

vars:	x(0), 
	NumDataStreams(0); 
 
for x = 1 to 50 begin  
	if BarStatus( x ) > 0 then begin  
		NumDataStreams = x;
	end;
end;

Normally, any reference to a datastream that doesn’t exist causes a run-time error. BarStatus allows us to check for the existence of datastreams without erroring. Also see the Automatically detecting the datastreams on a chart page.

Common Questions & Issues

  1. When using ‘open next bar’ terminology in my strategy, BarStatus only every returns ‘0’. Is this right?
    Yes, this is the way that BarStatus works.
  2. Why doesn’t BarStatus return a ‘0’ on the opening tick of a bar like it says in the documentation?
    This is a misreading of the documentation. BarStatus will only return ‘0’ when used in Strategies with ‘open next bar’ type terminology. Otherwise it will return ‘1’ for an intrabar tick, ‘2’ for an end of bar tick, or ‘-1’ for an error.

Related Pages

Enhancement Suggestions

OncePerBar