I'm trying to convert a NT7 version of the Arnaud Legoux Moving Average to NT8. As a beginner coder, I'm just following guidance in moving the code around and could be getting completely wrong but the compiler is giving me only one error message relating to plotting. Appreciate any help. I've attached the original NT7 code if it helps.
namespace NinjaTrader.NinjaScript.Indicators { public class ALMA : Indicator { private int iWindowSize = 9; private double iM_Sigma = 6.0; private double iP_Sample = 0.5; private double[] aALMA; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "ALMA"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = false; 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; AddPlot(Brushes.Orange, "ALMA_Plot"); } else if (State == State.Configure) { } } protected override void OnBarUpdate() { if (CurrentBar < iWindowSize) return; int pt = 0; double agr = 0; double norm = 0; for (int i = 0; i < iWindowSize; i++) { if (i < iWindowSize - pt) { agr += aALMA[i] * Close[iWindowSize - pt - 1 - i]; norm += aALMA[i]; } } // Normalize the result if (norm != 0) agr /= norm; // Set the approrpiate bar. //ALMA_Plot.Set(agr); } #region helper private void ResetWindow() { double m = (int)Math.Floor(iP_Sample * (double)(iWindowSize - 1)); double s = iWindowSize; s /= iM_Sigma; for (int i = 0; i < iWindowSize; i++) { aALMA[i] = Math.Exp(-((((double)i)-m)*(((double)i)-m))/(2*s*s)); } } #endregion #region Properties [Browsable(false)] [XmlIgnore] public Series<double> ALMA_Plot { get { return Values[0]; } } [Description("Sample point. Where in terms of the window should we take the current value (0-1)")] [Category("Parameters")] public double SamplePoint { get { return iP_Sample; } set { iP_Sample = Math.Min(Math.Max(0.0, value), 1.0); } } [Description("ALMA period. Must be an odd number.")] [Category("Parameters")] public int WindowSize { get { return iWindowSize; } set { iWindowSize = Math.Min(Math.Max(1, value), 50); // Only odd sizes if ((iWindowSize & 1) == 0) { iWindowSize++; } //ResetWindow(); } } [Description("Precision / Smoothing")] [Category("Parameters")] public double Sigma { get { return iM_Sigma; } set { iM_Sigma = Math.Min(Math.Max(0.01, value), 50.0); //ResetWindow(); } } #endregion } }
Comment