Beispiel #1
0
        /*  Similar to AggM, the AggZ is a composite trend and mean-reversion indicator rolled into one.
         * The concept of both is to anchor a long term trending measure to a short-term mean-reverting measure so that you can have an indicator
         * that can be traded for both long and short-term intervals. The calculation is dead simple:
         *
         * AggZ= (-1x( 10-day z-score)+(200-day z-score))/2
         * where z-score = (close-sma (closing prices over last n periods))/(standard deviation( closing prices over last n periods))
         *
         * buy above 0, sell below 0 as a basic strategy.
         * Users may try different variations of z-lengths as well as entry/exits.
         */

        public AggZ(DataSeries ds, int period1, int period2, StdDevCalculation sd, string description)
            : base(ds, description)
        {
            base.FirstValidValue = Math.Max(period1, period2);

            if (base.FirstValidValue < 2)
            {
                base.FirstValidValue = 2;
            }

            DataSeries sma10  = Community.Indicators.FastSMA.Series(ds, period1);
            DataSeries sma200 = Community.Indicators.FastSMA.Series(ds, period2);
            StdDev     sd10   = StdDev.Series(ds, period1, sd);
            StdDev     sd200  = StdDev.Series(ds, period2, sd);

            var rangePartitioner = Partitioner.Create(FirstValidValue, ds.Count);

            Parallel.ForEach(rangePartitioner, (range, loopState) =>
            {
                for (int bar = range.Item1; bar < range.Item2; bar++)
                {
                    double zscore10  = (ds[bar] - sma10[bar]) / sd10[bar];
                    double zscore200 = (ds[bar] - sma200[bar]) / sd200[bar];
                    double aggz      = (-1 * zscore10 + zscore200) / 2.0d;
                    base[bar]        = aggz;
                }
            });
        }
Beispiel #2
0
        public VarianceRatio(Bars bars, DataSeries ds, int lookback, int period, string description)
            : base(bars, description)
        {
            LNRet             lnr    = LNRet.Series(bars, ds, lookback);
            LNRet             lnr1   = LNRet.Series(bars, ds, 1);
            StdDevCalculation sample = StdDevCalculation.Sample;

            for (int bar = Math.Max(lookback, period); bar < bars.Count; bar++)
            {
                base[bar] = StdDev.Series(lnr, period, sample)[bar] / (StdDev.Series(lnr1, period, sample)[bar] * Math.Sqrt(lookback));
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public static AggZ Series(DataSeries ds, int period1, int period2, StdDevCalculation sd)
        {
            string description = string.Concat(new object[] { "AggZ(", ds.Description, ",", period1, ",", period2, ",", sd, ")" });

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

            AggZ _AggZ = new AggZ(ds, period1, period2, sd, description);

            ds.Cache[description] = _AggZ;
            return(_AggZ);
        }
Beispiel #5
0
        public BBandLower2(DataSeries ds, int period, double stdDevs, StdDevCalculation sd, string description)
            : base(ds, description)
        {
            base.FirstValidValue = period;

            if (FirstValidValue > ds.Count || FirstValidValue < 0)
            {
                FirstValidValue = ds.Count;
            }
            if (ds.Count < period)
            {
                return;
            }

            StdDev     sd_ = StdDev.Series(ds, period, sd);
            DataSeries sma = Community.Indicators.FastSMA.Series(ds, period);

            for (int bar = FirstValidValue; bar < ds.Count; bar++)
            {
                base[bar] = sma[bar] - (sd_[bar] * stdDevs);
            }
        }
Beispiel #6
0
        public MACZ(DataSeries ds, int period1, int period2, double A, double B, StdDevCalculation sdc, string description)
            : base(ds, description)
        {
            base.FirstValidValue = Math.Max(period1, period2);

            if (base.FirstValidValue < 2)
            {
                base.FirstValidValue = 2;
            }

            FirstValidValue *= 3; // EMA, the component of MACD, is an unstable indicator

            DataSeries sma    = Community.Indicators.FastSMA.Series(ds, period2);
            StdDev     sd     = StdDev.Series(ds, period2, sdc);
            DataSeries ZScore = (ds - sma) / sd;
            DataSeries macd   = EMA.Series(ds, period1, EMACalculation.Modern) - EMA.Series(ds, period2, EMACalculation.Modern);

            DataSeries MACZ = (ZScore * A) + (macd / sd * B);

            for (int bar = FirstValidValue; bar < ds.Count; bar++)
            {
                base[bar] = MACZ[bar];
            }
        }
Beispiel #7
0
        public static MACZ Series(DataSeries ds, int period1, int period2, double A, double B, StdDevCalculation sdc)
        {
            string description = string.Concat(new object[] { "MACZ(", ds.Description, ",", period1, ",", period2, ",",
                                                              A, ",", B, ",", sdc, ")" });

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

            MACZ _MACZ = new MACZ(ds, period1, period2, A, B, sdc, description);

            ds.Cache[description] = _MACZ;
            return(_MACZ);
        }