I used the Output window and the chart "Show Data Box" to debug. The array CalValue holds the indicator values, but these values do not match those in the "Show Data Box". Is there something wrong with the Set() command? Or I should shift the bar back or something? I even removed the script from the indicator folder, used a new name for the script, and even re-installed NT 7 but the same problem still persisted.
Please see the script and the Output window below.
************************************************** **************
public class TCMA5 : Indicator
{
#region Variables
private bool smooth = true; // Default setting is true
private DataSeries mySMA;
private double[] CalValue;
private double[] Sum;
private double[] Sumw;
#endregion
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Middle"));
mySMA = new DataSeries(this);
CalValue = new double[50];
Sum = new double[50]; // NT7 limits the number of available bars for calculations at 256
Sumw = new double[50];
Overlay = true;
}
protected override void OnBarUpdate()
{
if (CurrentBar <= 5) return;
Print(" ");
mySMA[0] = SMA(Input, 0)[0];
for (int i = 20; i >= 0; i--)
{
Sum[i] = 9 * mySMA[i];
Sumw[i] = 9;
int k = 8;
for (int j = 1; j <= 8; j++)
{
Sum[i] += k * mySMA[i+j];
Sumw[i] += k;
if (smooth==true & j <= i)
{
Sum[i] += k * mySMA[i-j];
Sumw[i] += k;
}
k--;
}
CalValue[i] = Sum[i] / Sumw[i];
}
/// Plot the array CalValue
for (int p = 0; p <= 20-1; p++)
{
Print("CalValue[" + p.ToString() + "] = " + CalValue[p].ToString());
}
Values[0].Set(CalValue[0]);
}
#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 Middle
{
get { return Values[0]; }
}
[Description("")]
[GridCategory("Parameters")]
public bool Smooth
{
get { return smooth; }
set { smooth = value; }
}
#endregion
}
************************************************** ***************************
These are the values from the Output Window (input: smooth = true). The chart is a daily chart of the stock XOM:
*****************************************
CalValue[0] = 88.6862222222222
CalValue[1] = 88.5771698113207
CalValue[2] = 88.4696666666667
CalValue[3] = 88.3572727272727
CalValue[4] = 88.2442253521127
CalValue[5] = 88.1388
CalValue[6] = 88.0338461538461
CalValue[7] = 87.925625
CalValue[8] = 87.8082716049383
CalValue[9] = 87.7025925925926
CalValue[10] = 87.6198765432098
CalValue[11] = 87.5351851851851
CalValue[12] = 87.4653086419753
CalValue[13] = 87.4077777777778
CalValue[14] = 87.3669135802469
CalValue[15] = 87.3176543209876
CalValue[16] = 87.307037037037
CalValue[17] = 87.3366666666666
CalValue[18] = 87.3922222222222
CalValue[19] = 87.4985185185185
************************************************** *
However, each time the chart plots the following values. Basically, the ninjascript works fine, but the chart only plots values as if the input "smooth" is set to zero. Why?
**************************************
CalValue[0] = 88.6862222222222
CalValue[1] = 88.3988888888889
CalValue[2] = 88.2133333333333
CalValue[3] = 88.048
CalValue[4] = 87.9091111111111
CalValue[5] = 87.8384444444444
CalValue[6] = 87.5957777777777
CalValue[7] = 87.5348888888889
CalValue[8] = 87.4088888888889
CalValue[9] = 87.4468888888888
CalValue[10] = 87.4566666666666
CalValue[11] = 87.3546666666666
CalValue[12] = 87.3675555555555
CalValue[13] = 87.3731111111111
CalValue[14] = 87.3708888888888
CalValue[15] = 87.0395555555555
CalValue[16] = 87.1595555555555
CalValue[17] = 87.2768888888888
CalValue[18] = 87.3608888888888
CalValue[19] = 87.6359999999999
************************************************

Comment