GetValueAt()

View as Markdown

Definition

Returns the underlying input value at a specified bar index value.

Method Return Value

A double value representing the value at a specified bar.

Syntax

GetValueAt(int barIndex)

ISeries\<t\>.GetValueAt(int barIndex)

If called directly from the instance of the NinjaScript object, the value which is returned corresponds to the input series the object is running. (e.g., Close, High, Low, SMA, etc.). If you’re attempting to obtain another indicator value, you will need to pull this from the calculated indicator Value or Plot:

SMA(20).GetValueAt(123); // bar value
SMA(20).Values[0].GetValueAt(123); // indicator value
(Input as Indicator).Values[0].GetValueAt(123) // passed in indicator value

Parameters

ParameterDescription
barIndexAn int representing an absolute bar index value

Examples

1protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
2{
3 // make sure there are bars displayed on the chart and the chart control is ready before running
4 if (Bars == null || chartControl == null)
5 return;
6
7 // loop through all the visible bars on the chart
8 for (int i = ChartBars.FromIndex - 1; i >= BarsRequiredToPlot; i--)
9 {
10 double value = GetValueAt(i);
11 Print(string.Format("The value at bar {0} is {1}", i, value));
12 }
13}