/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            bars.update();
            var maval = smoother.next(Input[0]);

            band.update(Input[0], maval);
            BandHigh.Set(bandSmoother1.next(band.UpperBand));
            BandLow.Set(bandSmoother2.next(band.LowerBand));
            MidLine.Set(maval);
        }
Example #2
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            var oldHigh  = bars.High;
            var oldClose = bars.Close;
            var oldLow   = bars.Low;

            bars.update();

            // true range...
            var trval = truerange.next(Math.Max(bars.High - bars.Low,
                                                Math.Max(bars.High - oldClose, oldClose - bars.Low)));

            if (trval == 0.0)
            {
                trval = 0.000001;
            }

            // RWT try upmove/dnmove = Median[0] - Median[1];
            // instead of High - Close[1] , Close[1] - Low[0];
            var upmove = Math.Max(0, bars.High - oldHigh);
            var dnmove = Math.Max(0, oldLow - bars.Low);

            if (upmove > dnmove)
            {
                dnmove = 0;
            }
            else
            {
                upmove = 0;
            }

            var dplusval = dplus.next(upmove);
            var dminval  = dminus.next(dnmove);

            var dmiplus  = 100.0 * dplusval / trval;
            var dmiminus = 100.0 * dminval / trval;

            var dmisum  = dmiplus + dmiminus;
            var dmidiff = Math.Abs(dmiplus - dmiminus);
            var adxval  = 100.0 * adx.next((dmisum > 0)?(dmidiff / dmisum):0.5);

            ADX.Set(adxval);
            if (adxval < oldADX)
            {
                PlotColors[0][0] = Color.Gray;
            }
            DMPlus.Set(dmiplus);
            DMMinus.Set(dmiminus);
            oldADX = adxval;
        }
Example #3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            habars.update();
            HAMid.Set((habars.High + habars.Low) * 0.5);
            HAHigh.Set(habars.High);
            HALow.Set(habars.Low);
            Color col;

            if (habars.Open < habars.Close)
            {
                col = ((habars.Low < habars.Open)?ltup:upcolor);
            }
            else
            {
                col = ((habars.High > habars.Open)?ltdn:dncolor);
            }
            PlotColors[0][0] = col;
            PlotColors[1][0] = col;
            PlotColors[2][0] = col;
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            bars.update();
            var nextFilt = filter.next((bars.High + bars.Low) * 0.5);
            var slope    = linreg.next(nextFilt);

            if ((nextFilt > lastFilt) &&
                (slope <= 0))
            {
                ProxyLine.Set(lastProxy);
            }
            else if ((nextFilt < lastFilt) &&
                     (slope >= 0))
            {
                ProxyLine.Set(lastProxy);
            }
            else
            {
                // either everything is flat, or the
                // med and slope agree...
                bool assumeUp = (slope > 0);
                if (slope == 0)
                {
                    if (nextFilt != lastFilt)
                    {
                        assumeUp = (nextFilt > lastFilt);
                    }
                    else
                    {
                        assumeUp = dirUp;
                    }
                }

                if (assumeUp)
                {
                    ProxyLine.Set(Math.Max(lastProxy, nextFilt));
                }
                else
                {
                    ProxyLine.Set(Math.Min(lastProxy, nextFilt));
                }
            }

            var newDirUp = dirUp;

            if (ProxyLine[0] > lastProxy)
            {
                newDirUp = true;
            }
            else if (ProxyLine[0] < lastProxy)
            {
                newDirUp = false;
            }

            bool upbar = bars.Close > bars.Open;
            bool dnbar = bars.Close < bars.Open;

            // if we're based on bars, use the actual bars themselves, too...
            if (onBasicBars)
            {
                upbar = upbar || (Close[0] > Open[0]) || (High[0] == Close[0]);
                dnbar = dnbar || (Close[0] < Open[0]) || (Low[0] == Close[0]);
            }

            double upRefLoc = 0;
            double dnRefLoc = 0;

            if (onBasicBars)
            {
                upRefLoc = High[0];
                dnRefLoc = Low[0];
            }
            else
            {
                upRefLoc = Input[0];
                dnRefLoc = Input[0];
            }

            // exceptions that hold the proxy in place for a bit...
            if ((!newDirUp && dirUp && upbar) ||
                (newDirUp && !dirUp && dnbar) ||
                (!newDirUp && dirUp && (lastProxy <= (upRefLoc + actualTolerance))) ||
                (newDirUp && !dirUp && (lastProxy >= (dnRefLoc - actualTolerance))) ||
                ((ProxyLine[0] > lastProxy) && (dnbar || (upRefLoc < ProxyLine[0]))) ||
                ((ProxyLine[0] < lastProxy) && (upbar || (dnRefLoc > ProxyLine[0])))
                )
            {
                newDirUp = dirUp;
                ProxyLine.Set(lastProxy);
            }

            PlotColors[0][0] = (newDirUp?upColor:dnColor);
            dirUp            = newDirUp;
            lastFilt         = nextFilt;
            lastProxy        = ProxyLine[0];
        }