Please find listed below the code:
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Reference sample demonstrating how to use DataSeries objects to store self calculations.
/// </summary>
[Description("Reference sample demonstrating how to use DataSeries objects to store self calculations.")]
public class svSDdiff : Indicator
{
#region Variables
private int period = 5;
// Defines the DataSeries object
private DataSeries myDataSeries;
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
// Adds a plot to our NinjaScript Indicator
Add(new Plot(Color.Orange, PlotStyle.Line, "Average Range"));
// Create a new DataSeries object and assign it to the variable myDataSeries declared in the ‘Variables’ region above
myDataSeries = new DataSeries(this);
CalculateOnBarClose = true;
Overlay = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
/* To set values to our DataSeries we use the Set() method. Here we are setting the DataSeries
object for the current bar to take on the absolute value of the difference between the current bar's
open and close. */
myDataSeries.Set(StdDev(Close,14)[1]-StdDev(Close,14)[0]);
/* Take note that the method for setting the value to be plotted is the same as for setting a value
to a DataSeries object. The difference here is that the custom DataSeries object is not plotted while
this "AvgR" is plotted.
In this case we are plotting the Simple Moving Average of the intermediate calculation step stored in our
DataSeries object. */
AvgR.Set(SMA(myDataSeries, Period)[0]);
}
Comment