Exemple #1
0
        public VWAP(Bars bars, string description)
            : base(bars, description)
        {
            Helper.CompatibilityCheck();

            base.FirstValidValue = 1;

            //Can't work if data isn't intraday
            if (!bars.IsIntraday)
            {
                return;
            }

            double x    = 0;
            double MVol = 0;

            //First, compute the typical price for the intraday period. This is the average of the high, low and close {(H+L+C)/3)}.
            AveragePrice ap = AveragePrice.Series(bars);

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                // daily initialization
                if (bars.IntradayBarNumber(bar) == 0)
                {
                    x    = 0;
                    MVol = 0;

                    //20180413 fix for not taking the intraday bar 0 value, replacing it with the prior day VWAP closing value
                    //if (bar > 0)
                    //    base[bar] = base[bar - 1];
                }
                //else  //20180413 fix for not taking the intraday bar 0 value, replacing it with the prior day VWAP closing value
                {
                    //Second, multiply the typical price by the period's volume.
                    //Third, create a running total of these values. This is also known as a cumulative total.
                    x += ap[bar] * bars.Volume[bar];

                    //Fourth, create a running total of volume (cumulative volume).
                    MVol += bars.Volume[bar];

                    //Fifth, divide the running total of price-volume by the running total of volume.
                    base[bar] = x / MVol;
                }

                // Old version (prior to 2012.04)

                /*x += ap[bar] * bars.Volume[bar];
                 * MVol += bars.Volume[bar];
                 * if (MVol == 0)
                 *  base[bar] = ap[bar];
                 * else
                 *  base[bar] = x / MVol;*/
            }
        }
Exemple #2
0
        public DV2(Bars bars, string description)
            : base(bars, description)
        {
            base.FirstValidValue = 2;

            DataSeries dv2 = bars.Close / AveragePrice.Series(bars) - 1;

            dv2 = (dv2 + (dv2 >> 1)) / 2d;

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                base[bar] = dv2[bar];
            }
        }
Exemple #3
0
        public AwesomeOscillator(Bars bars, int period1, int period2, string description)
            : base(bars, description)
        {
            base.FirstValidValue = period1 + period2;

            AveragePrice avg = AveragePrice.Series(bars);

            var rangePartitioner = Partitioner.Create(0, bars.Count);

            Parallel.ForEach(rangePartitioner, (range, loopState) =>
            {
                for (int bar = range.Item1; bar < range.Item2; bar++)
                {
                    base[bar] = Community.Indicators.FastSMA.Series(avg, period1)[bar] - Community.Indicators.FastSMA.Series(avg, period2)[bar];
                }
            });
        }