/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double cup = 0;
            double cdn = 0;

            lf.Update();

            for (int i = 0; i < (len - 1); ++i)
            {
                var diff = lf.filtered(i) - lf.filtered(i + 1);
                if (diff >= 0)
                {
                    cup += diff;
                }
                else
                {
                    cdn += -diff;
                }
            }

            if ((cup + cdn) > 0)
            {
                Value.Set(cup / (cup + cdn));
            }
        }
        /// <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]);
        }
Пример #3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            lf.Update();

            double favg = 0;
            double savg = 0;

            for (int i = 0; i < fastLen; ++i)
            {
                favg += lf.filtered(i);
            }
            savg = favg;
            for (int i = fastLen; i < slowLen; ++i)
            {
                savg += lf.filtered(i);
            }

            savg /= slowLen;
            favg /= fastLen;

            double diff = favg - savg;

            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            MACDVal.Set(diff);
            if (CurrentBar > 1)
            {
                TriggerVal.Set(TriggerVal[1] + (2.0 / (trigger + 1.0)) * (diff - TriggerVal[1]));
                HistogramVal.Set(diff - TriggerVal[0]);
            }
            else
            {
                TriggerVal.Set(diff);
                HistogramVal.Set(0);
            }
        }