Exemplo n.º 1
0
        /// <summary>
        /// The VWMA (Volume-Weighted Moving Average) returns the volume-weighted moving average for the specified price series and period. VWMA is similar to a Simple Moving Average (SMA), but each bar of data is weighted by the bar's Volume. VWMA places more significance on the days with the largest volume and the least for the days with lowest volume for the period specified.
        /// </summary>
        /// <returns></returns>
        public VWMA VWMA(Data.IDataSeries input, int period)
        {
            if (cacheVWMA != null)
            {
                for (int idx = 0; idx < cacheVWMA.Length; idx++)
                {
                    if (cacheVWMA[idx].Period == period && cacheVWMA[idx].EqualsInput(input))
                    {
                        return(cacheVWMA[idx]);
                    }
                }
            }

            lock (checkVWMA)
            {
                checkVWMA.Period = period;
                period           = checkVWMA.Period;

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

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

                VWMA[] tmp = new VWMA[cacheVWMA == null ? 1 : cacheVWMA.Length + 1];
                if (cacheVWMA != null)
                {
                    cacheVWMA.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheVWMA           = tmp;
                return(indicator);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The VWMA (Volume-Weighted Moving Average) returns the volume-weighted moving average for the specified price series and period. VWMA is similar to a Simple Moving Average (SMA), but each bar of data is weighted by the bar's Volume. VWMA places more significance on the days with the largest volume and the least for the days with lowest volume for the period specified.
        /// </summary>
        /// <returns></returns>
        public VWMA VWMA(Data.IDataSeries input, int period)
        {
            if (cacheVWMA != null)
                for (int idx = 0; idx < cacheVWMA.Length; idx++)
                    if (cacheVWMA[idx].Period == period && cacheVWMA[idx].EqualsInput(input))
                        return cacheVWMA[idx];

            lock (checkVWMA)
            {
                checkVWMA.Period = period;
                period = checkVWMA.Period;

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

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

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