public class OpenMinusCloseIndicator : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Calculates the Open - Close";
Name = "OpenMinusCloseIndicator";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 0)
{
return;
}
OpenMinusClose[0] = Open[0] - Close[0];
}
#region Properties
[Browsable(false)]
[XmlIgnore()]
public Series<double> OpenMinusClose
{
get {
// EXCEPTION IS HERE on the first access in my strategy
return Values[0];
}
}
#endregion
}
// First access to this in my strategy produces the error commented above
Print("OpenMinusClose: " + openMinusCloseIndicator.OpenMinusClose[0]);
openMinusCloseIndicator = OpenMinusCloseIndicator();
Here are my questions and confusions:
* What does Values in the indicator refer to. Yes it refers to a series, but how is the data populated I can't find it in the docs? What if I want multiple indexes with different values to Values, like Values[0] and Values[1]. What exactly determines the order in which those Values indexes are set in the indicator?
* For example if I wanted to add CloseMinusOpen in addition to OpenMinusClose, how do I know that refers to index 0 or 1 into Values?
Again this is just a test to help me wrap my mind around having multiple calculations within an indicator. I've studied the RSI.cs indicator as a reference, and the Default[0] and Avg[0] are being set, and I seem to be copying how it is doing that, but still getting an exception, please help!

Comment