Exemplo n.º 1
0
        public BBPctB(DataSeries ds, int period, double SD, string description)
            : base(ds, description)
        {
            DataSeries BBUp   = BBandUpper2.Series(ds, period, SD, StdDevCalculation.Sample);
            DataSeries BBDown = BBandLower2.Series(ds, period, SD, StdDevCalculation.Sample);
            DataSeries PctBBW = ((ds - BBDown) / (BBUp - BBDown));  //%B = (Price - Lower Band)/(Upper Band - Lower Band)

            base.FirstValidValue = ds.FirstValidValue;

            for (int bar = FirstValidValue; bar < ds.Count; bar++)
            {
                double v = PctBBW[bar];
                base[bar] = (double.IsInfinity(v) || double.IsNaN(v)) ? 0 : v;
                //base[bar] = ((ds[bar] - BBDown[bar]) / (BBUp[bar] - BBDown[bar]));
            }
        }
Exemplo n.º 2
0
        public BBWidth(DataSeries ds, int period, double SD, bool percent, string description)
            : base(ds, description)
        {
            DataSeries BBUp   = BBandUpper2.Series(ds, period, SD, StdDevCalculation.Sample);
            DataSeries BBDown = BBandLower2.Series(ds, period, SD, StdDevCalculation.Sample);

            Community.Indicators.FastSMA sma = Community.Indicators.FastSMA.Series(ds, period);
            DataSeries bbWidth = (BBUp - BBDown) / sma;     //BandWidth = (upperBB − lowerBB) / middleBB

            base.FirstValidValue = ds.FirstValidValue;

            for (int bar = FirstValidValue; bar < ds.Count; bar++)
            {
                if (!percent)
                {
                    base[bar] = bbWidth[bar];
                }
                else
                {
                    base[bar] = bbWidth[bar] * 100;
                }
            }
        }