BarsPeriod

<< Click to Display Table of Contents >>

Navigation:  NinjaScript > Language Reference > Common > OnBarUpdate() >

BarsPeriod

Previous page Return to chapter overview Next page

Definition

The primary Bars object time frame (period type and interval).
 

Warning:  This property should NOT be accessed within the OnStateChange() method before the State has reached State.DataLoaded

 

 

Property Value

A Bars series object representing the time frame of the Bars.

 

Syntax

BarsPeriod.BarsPeriodType

The type of bars used for the period.  Possible values:

BarsPeriodType.Tick
BarsPeriodType.Volume
BarsPeriodType.Second
BarsPeriodType.Range
BarsPeriodType.Minute
BarsPeriodType.Day
BarsPeriodType.Week
BarsPeriodType.Month
BarsPeriodType.Year

BarsPeriodType.HeikenAshi
BarsPeriodType.Kagi
BarsPeriodType.LineBreak
BarsPeriodType.PointAndFigure
BarsPeriodType.Renko

BarsPeriod.BaseBarsPeriodType

Only relevant for HeikenAshi, Kagi, LineBreak, and PointAndFigure Bars objects. Same possible values as BarsPeriod.BarsPeriodType

BarsPeriod.BaseBarsPeriodValue

Only relevant for HeikenAshi, Kagi, LineBreak, and PointAndFigure Bars objects. Determines an integer value representing the basePeriodTypeValue parameter

BarsPeriod.MarketDataType

The data type used to build the bars.  Possible values:

MarketDataType.Ask
MarketDataType.Bid
MarketDataType.Last

BarsPeriod.PointAndFigurePriceType

Only relevant for PointAndFigure Bars objects. Possible values:
PointAndFigurePriceType.Close
PointAndFigurePriceType.HighsAndLows

BarsPeriod.ReversalType

Only relevant for Kagi Bars objects. Possible values:
ReversalType.Percent
ReversalType.Tick

BarsPeriod.Value

Determines an integer value representing the period parameter.

When using Kagi Bars objects this represents the "reversal" parameter
When using LineBreak Bars objects this represents the "lineBreakCount" parameter
When using PointAndFigure Bars objects this represents the "boxSize" parameter
When using Renko Bars objects this represents the "brickSize" parameter

BarsPeriod.Value2

Only relevant for PointAndFigure Bars objects. Determines an integer value representing the "reversal" parameter.

 

 

Examples

ns

Checking BarsPeriod values


// Calculate only if there is a 100 tick chart or greater
protected override void OnBarUpdate()
{
    if (BarsPeriod.BarsPeriodType == BarsPeriodType.Tick && BarsPeriod.Value >= 100)
    {
        // Indicator calculation logic here
    }
}

 

 

ns

Creating a new BarsPeriod object


protected override void OnStateChange()
{
    if (State == State.Configure)
    {    
          // add a 1440 minute apple bars object using the RTH session template
          AddDataSeries("AAPL", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "US Equities RTH");              
    }
 
    else if (State == State.DataLoaded)
    {
          // Print out the loaded bars period
          Print(Instrument.FullName + " " + BarsPeriod); // MSFT 1 Minute
          Print(BarsArray[1].Instrument.FullName + " " + BarsArray[1].BarsPeriod); // AAPL 1440 Minute
    }
}