Beispiel #1
0
        /// <summary>
        /// The VMA (Variable Moving Average, also known as VIDYA or Variable Index Dynamic Average) is an exponential moving average that automatically adjusts the smoothing weight based on the volatility of the data series. VMA solves a problem with most moving averages. In times of low volatility, such as when the price is trending, the moving average time period should be shorter to be sensitive to the inevitable break in the trend. Whereas, in more volatile non-trending times, the moving average time period should be longer to filter out the choppiness. VIDYA uses the CMO indicator for it's internal volatility calculations. Both the VMA and the CMO period are adjustable.
        /// </summary>
        /// <returns></returns>
        public VMA VMA(Data.IDataSeries input, int period, int volatilityPeriod)
        {
            if (cacheVMA != null)
            {
                for (int idx = 0; idx < cacheVMA.Length; idx++)
                {
                    if (cacheVMA[idx].Period == period && cacheVMA[idx].VolatilityPeriod == volatilityPeriod && cacheVMA[idx].EqualsInput(input))
                    {
                        return(cacheVMA[idx]);
                    }
                }
            }

            lock (checkVMA)
            {
                checkVMA.Period           = period;
                period                    = checkVMA.Period;
                checkVMA.VolatilityPeriod = volatilityPeriod;
                volatilityPeriod          = checkVMA.VolatilityPeriod;

                if (cacheVMA != null)
                {
                    for (int idx = 0; idx < cacheVMA.Length; idx++)
                    {
                        if (cacheVMA[idx].Period == period && cacheVMA[idx].VolatilityPeriod == volatilityPeriod && cacheVMA[idx].EqualsInput(input))
                        {
                            return(cacheVMA[idx]);
                        }
                    }
                }

                VMA indicator = new VMA();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input            = input;
                indicator.Period           = period;
                indicator.VolatilityPeriod = volatilityPeriod;
                Indicators.Add(indicator);
                indicator.SetUp();

                VMA[] tmp = new VMA[cacheVMA == null ? 1 : cacheVMA.Length + 1];
                if (cacheVMA != null)
                {
                    cacheVMA.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheVMA            = tmp;
                return(indicator);
            }
        }
Beispiel #2
0
        /// <summary>
        /// The VMA (Variable Moving Average, also known as VIDYA or Variable Index Dynamic Average) is an exponential moving average that automatically adjusts the smoothing weight based on the volatility of the data series. VMA solves a problem with most moving averages. In times of low volatility, such as when the price is trending, the moving average time period should be shorter to be sensitive to the inevitable break in the trend. Whereas, in more volatile non-trending times, the moving average time period should be longer to filter out the choppiness. VIDYA uses the CMO indicator for it's internal volatility calculations. Both the VMA and the CMO period are adjustable.
        /// </summary>
        /// <returns></returns>
        public VMA VMA(Data.IDataSeries input, int period, int volatilityPeriod)
        {
            if (cacheVMA != null)
                for (int idx = 0; idx < cacheVMA.Length; idx++)
                    if (cacheVMA[idx].Period == period && cacheVMA[idx].VolatilityPeriod == volatilityPeriod && cacheVMA[idx].EqualsInput(input))
                        return cacheVMA[idx];

            lock (checkVMA)
            {
                checkVMA.Period = period;
                period = checkVMA.Period;
                checkVMA.VolatilityPeriod = volatilityPeriod;
                volatilityPeriod = checkVMA.VolatilityPeriod;

                if (cacheVMA != null)
                    for (int idx = 0; idx < cacheVMA.Length; idx++)
                        if (cacheVMA[idx].Period == period && cacheVMA[idx].VolatilityPeriod == volatilityPeriod && cacheVMA[idx].EqualsInput(input))
                            return cacheVMA[idx];

                VMA indicator = new VMA();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.Period = period;
                indicator.VolatilityPeriod = volatilityPeriod;
                Indicators.Add(indicator);
                indicator.SetUp();

                VMA[] tmp = new VMA[cacheVMA == null ? 1 : cacheVMA.Length + 1];
                if (cacheVMA != null)
                    cacheVMA.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheVMA = tmp;
                return indicator;
            }
        }