ChartBars

<< Click to Display Table of Contents >>

Navigation:  NinjaScript > Language Reference > Common > Charts >

ChartBars

Previous page Return to chapter overview Next page

The ChartBars class provides GUI access related methods and properties to the primary bars series configured on the Chart through the Data Series menu.   For data access information related to the NinjaScript input's bars series, please use the Bars Series object (or the BarsArray for multi-series input)

 

Note:  A ChartBars object will ONLY exist should the hosting NinjaScript type be loaded through a Chart.  For example, a Strategy would have access to a ChartBars property when running on a Chart, but would NOT when loaded through the Strategies Grid or Strategy analyzer.  

 

 

ChartBars

 

 

Warning:  It is crucial to check for object references before accessing the ChartBars otherwise possible null reference errors can be expected depending on where the NinjaScript object was started.  See example below

 

 

 

Methods and Properties

Bars

Data returned from the historical data repository.

Count

The total number of ChartBars that exist on the chart

FromIndex

An index value representing the first bar painted on the chart.  

GetBarIdxByTime()

An ChartBar index value calculated from a time value on the chart.

GetBarIdxByX()

Returns the ChartBar index value at a specified x-coordinate relative to the ChartControl.

GetTimeByBarIdx()

The ChartBars time value calculated from a bar index value on the chart.

Panel

The Panel index value that the ChartBars eside.

Properties

Various ChartBar properties that have been configured from the Chart's Data Series menu.

ToChartString()

A string formatted for the Chart's Data Series Label as well as the period.

ToIndex

An index value representing the last bar painted on the chart.  

 

 

Example

ns

protected override void OnStateChange()
{        
  if (State == State.DataLoaded)
  {
    if(ChartBars != null)
    {
        Print("The starting number of bars on the chart is " + ChartBars.Bars.Count);
    }
    else
    {
        Print("Strategy was not loaded from a chart, exiting strategy...");
        return;
    }
  }
}