Пример #1
0
        /// <summary>
        /// ADXVMA v2.0
        /// </summary>
        /// <returns></returns>
        public ADXVMA ADXVMA(Data.IDataSeries input, int aDXPeriod)
        {
            if (cacheADXVMA != null)
            {
                for (int idx = 0; idx < cacheADXVMA.Length; idx++)
                {
                    if (cacheADXVMA[idx].ADXPeriod == aDXPeriod && cacheADXVMA[idx].EqualsInput(input))
                    {
                        return(cacheADXVMA[idx]);
                    }
                }
            }

            lock (checkADXVMA)
            {
                checkADXVMA.ADXPeriod = aDXPeriod;
                aDXPeriod             = checkADXVMA.ADXPeriod;

                if (cacheADXVMA != null)
                {
                    for (int idx = 0; idx < cacheADXVMA.Length; idx++)
                    {
                        if (cacheADXVMA[idx].ADXPeriod == aDXPeriod && cacheADXVMA[idx].EqualsInput(input))
                        {
                            return(cacheADXVMA[idx]);
                        }
                    }
                }

                ADXVMA indicator = new ADXVMA();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input     = input;
                indicator.ADXPeriod = aDXPeriod;
                Indicators.Add(indicator);
                indicator.SetUp();

                ADXVMA[] tmp = new ADXVMA[cacheADXVMA == null ? 1 : cacheADXVMA.Length + 1];
                if (cacheADXVMA != null)
                {
                    cacheADXVMA.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheADXVMA         = tmp;
                return(indicator);
            }
        }
Пример #2
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar == 0)
            {
                ADXVMA.Set(Input[0]);
                return;
            }

            var curStoch = mystoch[0];
            var emaAlpha = 2.0 / (fastSpeed + (1.0 - curStoch) * (slowestSpeed - fastSpeed) + 1.0);

            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            ADXVMA.Set(ADXVMA[1] + emaAlpha * (Input[0] - ADXVMA[1]));
        }
Пример #3
0
        /// <summary>
        /// ADXVMA
        /// </summary>
        /// <returns></returns>
        public ADXVMA ADXVMA(Data.IDataSeries input, int aDXPeriod)
        {
            if (cacheADXVMA != null)
                for (int idx = 0; idx < cacheADXVMA.Length; idx++)
                    if (cacheADXVMA[idx].ADXPeriod == aDXPeriod && cacheADXVMA[idx].EqualsInput(input))
                        return cacheADXVMA[idx];

            lock (checkADXVMA)
            {
                checkADXVMA.ADXPeriod = aDXPeriod;
                aDXPeriod = checkADXVMA.ADXPeriod;

                if (cacheADXVMA != null)
                    for (int idx = 0; idx < cacheADXVMA.Length; idx++)
                        if (cacheADXVMA[idx].ADXPeriod == aDXPeriod && cacheADXVMA[idx].EqualsInput(input))
                            return cacheADXVMA[idx];

                ADXVMA indicator = new ADXVMA();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.ADXPeriod = aDXPeriod;
                Indicators.Add(indicator);
                indicator.SetUp();

                ADXVMA[] tmp = new ADXVMA[cacheADXVMA == null ? 1 : cacheADXVMA.Length + 1];
                if (cacheADXVMA != null)
                    cacheADXVMA.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheADXVMA = tmp;
                return indicator;
            }
        }
Пример #4
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 1)
            {
                up.Set(0);
                down.Set(0);
                ups.Set(0);
                downs.Set(0);
                index.Set(0);
                ADXVMA.Set(Input[0]);
            }
            else
            {
                double currentUp   = Math.Max(Input[0] - Input[1], 0);
                double currentDown = Math.Max(Input[1] - Input[0], 0);
                up.Set((1 - k) * up[1] + k * currentUp);
                down.Set((1 - k) * down[1] + k * currentDown);

                double sum          = up[0] + down[0];
                double fractionUp   = 0.0;
                double fractionDown = 0.0;
                if (sum > double.Epsilon)
                {
                    fractionUp   = up[0] / sum;
                    fractionDown = down[0] / sum;
                }
                ups.Set((1 - k) * ups[1] + k * fractionUp);
                downs.Set((1 - k) * downs[1] + k * fractionDown);

                double normDiff     = Math.Abs(ups[0] - downs[0]);
                double normSum      = ups[0] + downs[0];
                double normFraction = 0.0;
                if (normSum > double.Epsilon)
                {
                    normFraction = normDiff / normSum;
                }
                index.Set((1 - k) * index[1] + k * normFraction);

                if (FirstTickOfBar)
                {
                    epsilon = 0.1 * volatility[1];
                    hhp     = MAX(index, period)[1];
                    llp     = MIN(index, period)[1];
                }
                hhv = Math.Max(index[0], hhp);
                llv = Math.Min(index[0], llp);

                double vDiff  = hhv - llv;
                double vIndex = 0;
                if (vDiff > double.Epsilon)
                {
                    vIndex = (index[0] - llv) / vDiff;
                }

                ADXVMA.Set((1 - k * vIndex) * ADXVMA[1] + k * vIndex * Input[0]);

                if (trend[1] > -1 && ADXVMA[0] > ADXVMA[1] + epsilon)
                {
                    trend.Set(1);
                    PlotColors[0][0] = upColor;
                }
                else if (trend[1] < 1 && ADXVMA[0] < ADXVMA[1] - epsilon)
                {
                    trend.Set(-1);
                    PlotColors[0][0] = downColor;
                }
                else
                {
                    trend.Set(0);
                    PlotColors[0][0] = neutralColor;
                }

                if (showPaintBars)
                {
                    if (trend[0] == 1)
                    {
                        BarColor           = upColor;
                        CandleOutlineColor = upColor;
                    }
                    else if (trend[0] == -1)
                    {
                        BarColor           = downColor;
                        CandleOutlineColor = downColor;
                    }
                    else
                    {
                        BarColor           = neutralColor;
                        CandleOutlineColor = neutralColor;
                    }
                    if (candles && Close[0] > Open[0])
                    {
                        BarColor = Color.FromArgb(alpha, BarColor);
                    }
                }
            }
        }