NinjaScript > Language Reference > Data >
Working with Price Data
The core objective of developing custom Indicators and Strategies with NinjaScript is to evaluate price data. NinjaScript allows you to reference current and historical price data. There are several categories of price data which include Price Types, Indicator and Custom Historical Series.
Price Type - Standard bar based price types such as closing, opening, high, low prices and volume
Referencing Price Type Data
You will notice that to reference any price data you need to include a value for [int barsAgo]. This is a very simple concept; barsAgo represents the number of bars ago to reference and int indicates that barsAgo is an integer value. As an example, we could write a statement to check if the the high price of 1 bar ago is less than the high price of the current bar like this:
High < High;
You could write a statement to calculate the average closing price of the last three bars like this:
( Close + Close + Close ) / 3;
As you may have already figured out, referencing the current bar data is accomplished by passing in a value of 0 (zero) to the barsAgo parameter. Basically, we are saying show me the price data of zero bars ago, which means the current bar.
* Input is a special property that can be accessed and always points to the default price type. If you have an indicator that supports using different price type as its source data, if you reference the Input[in barsAgo] property it will automatically reference the correct price type object. This is an advanced topic.
Referencing Indicator Data
where indicator is the name of the indicator you want to access, parameters is any associated parameters the indicator requires and barsAgo is the number of bars we wish to offset from the current bar.
As an example, we could write a statement to check if the current closing price is greater than the 20 period simple moving average like this:
Close > SMA(20);
If you wanted to perform the same check but only check against a 20 period simple moving average of high prices you would write it like this:
Close > SMA(High, 20);
You could write a statement to see if a 14 period CCI indicator is rising like this:
CCI(14) > CCI(14);
Please review the Indicator Methods section for proper syntax for accessing different indicator values.