can anyone check the issue in this coding?
#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// IFTA2012 Moving Averages 3.0 by Manfred G. Dürschner /// </summary> [Description("IFTA2012 Moving Averages 3.0 by Manfred G. Dürschner")] public class nwMAMovAvg30alpha : Indicator { #region NWMA UTIl public IDataSeries NWMA(IDataSeries input, int cycle_period_n1, int cycle_period_n2,double alpha) { NMA =new DataSeries(this); MA1 =new DataSeries(this); MA2 =new DataSeries(this); //PRICE =new DataSeries(this);//MA2[MA1/ n2] /*error codes */ //PRICE.Set(input[0]); MA1.Set(WMA(input, cycle_period_n1)[0]); MA2.Set(WMA(MA1,cycle_period_n2)[0]); NMA.Set((1 +alpha)* MA1[0] -( alpha * MA2[0])); return NMA ; } #endregion // NWMA Calculations #region Variables // copyright stuff private const string _versionText = "V0.1Beta"; private const string _copyrightText = "All rights reserved to nTuple And KKS."; // Wizard generated variables private int cycle_Period_n1 = 21; // Default setting for Cycle_Period_n1 private int cycle_Period_n2 = 5; // Default setting for Cycle_Period_n2 private DataSeries NMA; private DataSeries MA1; private DataSeries MA2; private DataSeries PRICE; // User defined variables (add any user defined variables below) #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() { Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "NwMA")); Overlay = true; //Initializeparam(); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. /* α := L1/L2 = (n1 – 1)/(n2 – 1). In this expression denominator 2 for the SMA and EMA as well as denominator 3 for the WMA are missing. α is therefore valid for all three MAs. Using the Nyquist Criterion one gets for α the following result: (2) α = λ* (n1 – 1)/(n1 – λ). α put in (1) and C replaced by the approximation term NMA, the notation for the new MA, one gets: NMA = (1 +α) MA1 – α MA2. In detail, equation (2) reads as follows: (3) NMA[price/ n1, n2] = (1 + α) MA1[price/ n1 ] – α MA2[MA1/ n2], (4) α = λ* (n1 – 1)/(n1 – λ), with λ ≥ 2. (3) and (4) are equations for a group of MAs (notation: Moving Averages 3.0). They are independent of the choice of an MA. As the WMA shows the smallest lag (see introduction), it should generally be the first choice for the NMA. n1 = n2 results in the value 1 for α and λ, respectively. Then equation (3) passes into Ehlers´ formula. Thus Ehlers´ formula is included in the NMA formula as limiting value. It follows from a short calculation that the lag for NMA results in a theoretical value zero */ PRICE =new DataSeries(this); PRICE.Set((High[0]+Low[0])/2); double lamda=(cycle_Period_n1/cycle_Period_n2); if(lamda>=2) { double alpha = (lamda * (cycle_Period_n1 - 1))/(cycle_Period_n1 - lamda); //NMA = (1 +alpha)* SMA((Close/ period_n1),period_n2 ) - alpha * SMA(SMA/ n2); //PRICEc.Set((Open[0] + High[0] + Low[0] + Close[0]) / 4); NwMA.Set(NWMA(PRICE,cycle_Period_n1,cycle_Period_n2,alpha)[0]); } else if (cycle_Period_n1==cycle_Period_n2) { NwMA.Set(NWMA(PRICE,cycle_Period_n1,cycle_Period_n2,1)[0]); } else {Print("Please Some Other Values");} //NwMA.Set(Close[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 NwMA { get { return Values[0]; } } [Description("")] [GridCategory("Parameters")] public int Cycle_Period_n1 { get { return cycle_Period_n1; } set { cycle_Period_n1 = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int Cycle_Period_n2 { get { return cycle_Period_n2; } set { cycle_Period_n2 = Math.Max(1, value); } } #endregion #region Version Control [Description("Indicator version")] [Category(" Copyright (c)")] [Gui.Design.DisplayNameAttribute("Version")] public string VersionText { get { return _versionText; } } [Description(_copyrightText)] [Category(" Copyright (c)")] [Gui.Design.DisplayNameAttribute("Copyright 2015,2016,2017")] public string CopyrightText { get { return _copyrightText; } } #endregion }
Comment