Exemplo n.º 1
0
        public static BBandUpper2 Series(DataSeries ds, int period, double stdDevs, StdDevCalculation sd)
        {
            string description = string.Concat(new object[] { "Upper Bollinger Band(", ds.Description, ",", period, ",", stdDevs, ",", sd, ")" });

            if (ds.Cache.ContainsKey(description))
            {
                return((BBandUpper2)ds.Cache[description]);
            }

            BBandUpper2 _BBandUpper2 = new BBandUpper2(ds, period, stdDevs, sd, description);

            ds.Cache[description] = _BBandUpper2;
            return(_BBandUpper2);
        }
Exemplo n.º 2
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.º 3
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;
                }
            }
        }