I am trying to standardise the results of a custom indicator, so it can be used in different markets. To do this, I need to create a moving average of that indicator for say the last 100 bars, so I have something to divide by... but as far as i could work out, I needed to add the indicator as a second data series in order to be able to create a SMA of it.
Below is my formula, it is not currently showing anything, the problem appears to be with setting the second data series ("SlopeData") as the slope value. I am wondering if maybe when I calculate the 'Slope' of this indicator, it is trying to access the first data series instead of the second...?
Thanks for any help/advice... cheers
Shane
namespace NinjaTrader.Indicator
{
/// <summary>
/// Measures the slope of an SMA
/// </summary>
[Description("Measures the slope of an SMA")]
public class SlopeSMA : Indicator
{
#region Variables
private int sMAPeriod = 200; // Default setting for SMAPeriod
private int startBarsAgo = 5; // Default setting for StartBarsAgo
private int endBarsAgo = 0; // Default setting for EndBarsAgo
private double slope;
private DataSeries SlopeData;
#endregion
protected override void Initialize()
{
SlopeData = new DataSeries (this);
Add(new Plot(Color.FromKnownColor(KnownColor.RoyalBlue), PlotStyle.Line, "Plot0"));
Overlay = false;
}
protected override void OnBarUpdate()
{
SlopeData.Set(Slope(SMA(sMAPeriod), startBarsAgo, endBarsAgo));
slope = SMA(SlopeData,100)[0];
Plot0.Set((Slope(SMA(sMAPeriod), startBarsAgo, endBarsAgo) / slope)*100);
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}
public DataSeries Plot1
{
get { return Values[1]; }
}
public DataSeries Plot2
{
get { return Values[2]; }
}
[Description("Moving Aver Period")]
[GridCategory("Parameters")]
public int SMAPeriod
{
get { return sMAPeriod; }
set { sMAPeriod = Math.Max(1, value); }
}
[Description("Start Bars Ago")]
[GridCategory("Parameters")]
public int StartBarsAgo
{
get { return startBarsAgo; }
set { startBarsAgo = Math.Max(1, value); }
}
[Description("End Bars Ago")]
[GridCategory("Parameters")]
public int EndBarsAgo
{
get { return endBarsAgo; }
set { endBarsAgo = Math.Max(0, value); }
}
#endregion
}
}
Comment