Exemple #1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            EMA    ema1       = EMA(Input, Period);
            double difference = ema1[0] - EMA(ema1, Period)[0];

            ZLEMA.Set(ema1[0] + difference);
        }
Exemple #2
0
        /// <summary>
        /// The ZLEMA (Zero-Lag Exponential Moving Average) is an EMA variant that attempts to adjust for lag.
        /// </summary>
        /// <returns></returns>
        public ZLEMA ZLEMA(Data.IDataSeries input, int period)
        {
            if (cacheZLEMA != null)
            {
                for (int idx = 0; idx < cacheZLEMA.Length; idx++)
                {
                    if (cacheZLEMA[idx].Period == period && cacheZLEMA[idx].EqualsInput(input))
                    {
                        return(cacheZLEMA[idx]);
                    }
                }
            }

            lock (checkZLEMA)
            {
                checkZLEMA.Period = period;
                period            = checkZLEMA.Period;

                if (cacheZLEMA != null)
                {
                    for (int idx = 0; idx < cacheZLEMA.Length; idx++)
                    {
                        if (cacheZLEMA[idx].Period == period && cacheZLEMA[idx].EqualsInput(input))
                        {
                            return(cacheZLEMA[idx]);
                        }
                    }
                }

                ZLEMA indicator = new ZLEMA();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input  = input;
                indicator.Period = period;
                Indicators.Add(indicator);
                indicator.SetUp();

                ZLEMA[] tmp = new ZLEMA[cacheZLEMA == null ? 1 : cacheZLEMA.Length + 1];
                if (cacheZLEMA != null)
                {
                    cacheZLEMA.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheZLEMA          = tmp;
                return(indicator);
            }
        }