Пример #1
0
        /// <summary>
        /// The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.
        /// </summary>
        /// <returns></returns>
        public SJCEMA SJCEMA(Data.IDataSeries input, double period)
        {
            if (cacheSJCEMA != null)
            {
                for (int idx = 0; idx < cacheSJCEMA.Length; idx++)
                {
                    if (Math.Abs(cacheSJCEMA[idx].Period - period) <= double.Epsilon && cacheSJCEMA[idx].EqualsInput(input))
                    {
                        return(cacheSJCEMA[idx]);
                    }
                }
            }

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

                if (cacheSJCEMA != null)
                {
                    for (int idx = 0; idx < cacheSJCEMA.Length; idx++)
                    {
                        if (Math.Abs(cacheSJCEMA[idx].Period - period) <= double.Epsilon && cacheSJCEMA[idx].EqualsInput(input))
                        {
                            return(cacheSJCEMA[idx]);
                        }
                    }
                }

                SJCEMA indicator = new SJCEMA();
                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();

                SJCEMA[] tmp = new SJCEMA[cacheSJCEMA == null ? 1 : cacheSJCEMA.Length + 1];
                if (cacheSJCEMA != null)
                {
                    cacheSJCEMA.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheSJCEMA         = tmp;
                return(indicator);
            }
        }
Пример #2
0
 protected override void OnStartUp()
 {
     ema1 = SJCEMA(Input, period1);//SJCEMA(Close, period1);
     ema2 = SJCEMA(ema1, period2);
     ema3 = SJCEMA(ema2, period3);
 }