Exemplo n.º 1
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;
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar == 0)
            {
                fastEma.Set(Input[0]);
                macdAvg2.Set(Input[0]);
                Value.Set(0);
                Avg.Set(0);
                Diff.Set(0);
            }
            else
            {
                fastEma.Set((ZeroLagEMA(Input, (int)(Fast / Acceleration))[0]) - (ZeroLagEMA(Input, (int)(Slow / Acceleration))[0]));
                double macd = fastEma[0];

                macdAvg2.Set(ZeroLagEMA(fastEma, Smooth)[0]);
                double macdAvg = macdAvg2[0];

                Value.Set(macd);
                Avg.Set(macdAvg);
                ADX.Set(ADXVMA(Value, (int)(Fast / Acceleration))[0]);

                Diff.Set(macd - macdAvg);

                //Print (Time[0] + ": Value = " + Value[0].ToString("0.00") + ", Avg = " + Avg[0].ToString("0.00") + ", ADX = " + ADX[0].ToString("0.00"));

                if ((Value[0] > ADX[0]) && (Value[0] > Threshold))
                {
                    MacdUp.Set(0);
                    MacdDn.Reset();
                    MacdNeutral.Reset();
                    signal.Set(1);
                }
                else
                if ((Value[0] < ADX[0]) && (Value[0] < -Threshold))
                {
                    MacdDn.Set(0);
                    MacdUp.Reset();
                    MacdNeutral.Reset();
                    signal.Set(-1);
                }
                else
                {
                    MacdNeutral.Set(0);
                    MacdDn.Reset();
                    MacdUp.Reset();
                    signal.Set(0);
                }
            }
        }
Exemplo n.º 3
0
        protected override void OnStartUp()
        {
            var b1 = RWT_HA.OHLCFactory.createPrimary(barsType, Open, High, Low, Close, Input);

            bars = RWT_HA.OHLCFactory.createSecondary(b1, barSmoothType, barSmoothArg);

            truerange = RWT_MA.MAFactory.create(dMType, dMLength);
            dplus     = RWT_MA.MAFactory.create(dMType, dMLength);
            dminus    = RWT_MA.MAFactory.create(dMType, dMLength);
            adx       = RWT_MA.MAFactory.create(aDXType, aDXLength);
            truerange.init(bars.High - bars.Low);
            dplus.init(0);
            dminus.init(0);
            adx.init(.5);
            ADX.Set(0);
            oldADX = 0;
        }