/// <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.º 2
0
        protected override void OnBarUpdate()
        {
            if (CurrentBar == 0)
            {
                fastEma[0]  = Input[0];
                macdAvg2[0] = Input[0];
                Value[0]    = 0;
                Avg[0]      = 0;
                Diff[0]     = 0;
            }
            else
            {
                fastEma[0] = (ZeroLagEMA(Input, (int)(Fast / Acceleration))[0]) - (ZeroLagEMA(Input, (int)(Slow / Acceleration))[0]);
                double macd = fastEma[0];

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

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

                Diff[0] = macd - macdAvg;

                if ((Value[0] > ADX[0]) && (Value[0] > Threshold))
                {
                    MacdUp[0] = 0;
                    MacdDn.Reset();
                    MacdNeutral.Reset();
                    signal[0] = 1;
                }
                else
                {
                    if ((Value[0] < ADX[0]) && (Value[0] < -Threshold))
                    {
                        MacdDn[0] = 0;
                        MacdUp.Reset();
                        MacdNeutral.Reset();
                        signal[0] = -1;
                    }
                    else
                    {
                        MacdNeutral[0] = 0;
                        MacdDn.Reset();
                        MacdUp.Reset();
                        signal[0] = 0;
                    }
                }
            }
        }