예제 #1
0
        /// <summary>
        /// The WMA (Weighted Moving Average) is a Moving Average indicator that shows the average value of a security's price over a period of time with special emphasis on the more recent portions of the time period under analysis as opposed to the earlier.
        /// </summary>
        /// <returns></returns>
        public WMA WMA(Data.IDataSeries input, int period)
        {
            if (cacheWMA != null)
            {
                for (int idx = 0; idx < cacheWMA.Length; idx++)
                {
                    if (cacheWMA[idx].Period == period && cacheWMA[idx].EqualsInput(input))
                    {
                        return(cacheWMA[idx]);
                    }
                }
            }

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

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

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

                WMA[] tmp = new WMA[cacheWMA == null ? 1 : cacheWMA.Length + 1];
                if (cacheWMA != null)
                {
                    cacheWMA.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheWMA            = tmp;
                return(indicator);
            }
        }
 /// <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.Red), PlotStyle.Line, "ECO"));
     Add(new Plot(Color.FromKnownColor(KnownColor.Gold), PlotStyle.Line, "Trigger"));
     Add(new Plot(Color.FromKnownColor(KnownColor.Cyan), PlotStyle.Bar, "Histogram"));
     Add(new Line(Color.FromKnownColor(KnownColor.Blue), 0, "Zero"));
     Overlay            = false;
     PriceTypeSupported = false;
     Plots[0].Pen.Width = 2;
     Plots[1].Pen.Width = 2;
     Plots[2].Pen.Width = 2;
     weightma           = null;
     expma      = null;
     unsmoothed = new DataSeries(this);
 }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double value1 = 0.0;
            double value2 = 0.0;

            o.Update();
            h.Update();
            l.Update();
            c.Update();

            for (int i = 0; i < len; ++i)
            {
                value1 += (c.filtered(i) - o.filtered(i));
                value2 += (h.filtered(i) - l.filtered(i));
            }

            if (value2 != 0.0)
            {
                unsmoothed.Set(100.0 * value1 / value2);
            }
            else
            {
                if ((CurrentBar > 1) && unsmoothed.ContainsValue(1))
                {
                    unsmoothed.Set(unsmoothed[1]);
                }
                else
                {
                    unsmoothed.Set(0);
                }
            }

            if (weightma == null)
            {
                weightma = WMA(unsmoothed, smoothing);
                expma    = EMA(weightma.Value, trigger);
            }

            ECO.Set(weightma[0]);
            TriggerLine.Set(expma[0]);
            Histogram.Set(weightma[0] - expma[0]);
        }
예제 #4
0
 protected override void OnStartUp()
 {
     weightma    = null;
     expma       = null;
     ol          = new double[4];
     pol         = new double[4];
     hl          = new double[4];
     phl         = new double[4];
     ll          = new double[4];
     pll         = new double[4];
     cl          = new double[4];
     pcl         = new double[4];
     unsmoothed  = new DataSeries(this);
     lastSeenBar = -1;
     extdat      = Bars.BarsType as rwt.IExtendedData;
     if (extdat == null)
     {
         throw new Exception("Only use this indicator on an Extended Data BarType!");
     }
 }
예제 #5
0
 protected override void OnStartUp()
 {
     wma1 = WMA(Inputs[0], Period);
     wma2 = WMA(wma1, Period);
     wma3 = WMA(wma2, Period);
 }
예제 #6
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            var ed = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed == null)
            {
                return;
            }

            if (CurrentBar != lastSeenBar)
            {
                for (int i = 0; i < 4; ++i)
                {
                    pol[i] = ol[i];         // remember previous bar value...
                    phl[i] = hl[i];
                    pll[i] = ll[i];
                    pcl[i] = cl[i];
                }
                lastSeenBar = CurrentBar;
            }


            // update all the Laguerre numbers....
            ol[0] = (1 - gamma) * ed.dOpen + gamma * pol[0];
            hl[0] = (1 - gamma) * ed.dHigh + gamma * phl[0];
            ll[0] = (1 - gamma) * ed.dLow + gamma * pll[0];
            cl[0] = (1 - gamma) * ed.dClose + gamma * pcl[0];
            for (int i = 1; i < 4; ++i)
            {
                ol[i] = -gamma * ol[i - 1] + pol[i - 1] + gamma * pol[i];
                hl[i] = -gamma * hl[i - 1] + phl[i - 1] + gamma * phl[i];
                ll[i] = -gamma * ll[i - 1] + pll[i - 1] + gamma * pll[i];
                cl[i] = -gamma * cl[i - 1] + pcl[i - 1] + gamma * pcl[i];
            }

            double value1 = 0.0;
            double value2 = 0.0;

            for (int i = 0; i < 4; ++i)
            {
                value1 += (cl[i] - ol[i]);
                value2 += (hl[i] - ll[i]);
            }

            if (value2 != 0.0)
            {
                unsmoothed.Set(100.0 * value1 / value2);
            }
            else
            {
                if ((CurrentBar > 1) && unsmoothed.ContainsValue(1))
                {
                    unsmoothed.Set(unsmoothed[1]);
                }
                else
                {
                    unsmoothed.Set(0);
                }
            }

            if (weightma == null)
            {
                weightma = WMA(unsmoothed, smoothing);
                expma    = EMA(weightma.Value, trigger);
            }

            ECO.Set(weightma[0]);
            TriggerLine.Set(expma[0]);
            Histogram.Set(weightma[0] - expma[0]);
        }
예제 #7
0
        /// <summary>
        /// The WMA (Weighted Moving Average) is a Moving Average indicator that shows the average value of a security's price over a period of time with special emphasis on the more recent portions of the time period under analysis as opposed to the earlier.
        /// </summary>
        /// <returns></returns>
        public WMA WMA(Data.IDataSeries input, int period)
        {
            if (cacheWMA != null)
                for (int idx = 0; idx < cacheWMA.Length; idx++)
                    if (cacheWMA[idx].Period == period && cacheWMA[idx].EqualsInput(input))
                        return cacheWMA[idx];

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

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

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

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