In the following code the "smoothing" variable is always zero when it should be 1/period... What am I doing wrong here....
public class ibdMEMA : Indicator { //#region Variables private int period = 12; double smoothing = 1.0; private int debugLevel = 1; //SMA lo_SMA; //#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.Orange, "ibdMEMAVal")); Overlay = false; PriceTypeSupported = true; } protected override void OnStartUp() { } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { smoothing = (double)(1 / period); if (CurrentBar == period) { //smoothing = Math.Min(1, 1 / period); ibdMEMAVal.Set(Input[0]); } if (CurrentBar > period) { Print("smoothing = " + smoothing.ToString() + " CB: Input[0] = " + Input[0]); //IbdDebug("Value1 = " + Value[1] + " Input0 = " + Input[0], debugLevel, 1) ; //ibdMEMAVal.Set(( smoothing * Input[0] ) + ( ( 1 - smoothing ) * ibdMEMAVal[1])); ibdMEMAVal.Set(( .75 * Input[0] ) + ( ( 1 - .75 ) * ibdMEMAVal[1])); //IbdDebug("ibdMEMA Value during MEMA = " + ibdMEMAVal[0], debugLevel, 1) ; } } #region Properties [Browsable(false)] [XmlIgnore()] public DataSeries ibdMEMAVal { get { return Values[0]; } } /// <summary> /// </summary> [Description("Numbers of bars used for calculations")] [GridCategory("Parameters")] public int Period { get { return period; } set { period = Math.Max(1, value); } } #endregion }
Comment