Exemplo n.º 1
0
        public MSR(Bars bars, int per1, int per2, string description)
            : base(bars, description)
        {
            base.FirstValidValue = 252;

            //MSR= (10-day median of (H, L, C) – 20-day  MAX (H, L, C))/(20-day  MAX (H, L, C))
            //then take the 252-day percentrank of MSR or percentile ranking

            DataSeries msrTemp = new DataSeries(bars, "msrTemp(" + per1 + "," + per2 + ")");

            for (int bar = Math.Max(per1, per2); bar < bars.Count; bar++)
            {
                double        max20  = Highest.Series(bars.High, per2)[bar];
                List <double> prices = new List <double>(per1 * 3);
                for (int i = bar; i > bar - per1; i--)
                {
                    prices.Add(bars.High[i]); prices.Add(bars.Low[i]); prices.Add(bars.Close[i]);
                }

                prices.Sort();
                msrTemp[bar] = (GetMedian(prices) - max20) / max20;
            }

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                base[bar] = PercentRank.Series(msrTemp, 252)[bar];
                //base[bar] = PrcRank.Series(msrTemp, 252)[bar];
            }
        }
Exemplo n.º 2
0
        public ConnorsRSI(DataSeries ds, int periodRSI, int periodStreak, int periodPR, string description)
            : base(ds, description)
        {
            base.FirstValidValue = Math.Max(Math.Max(periodRSI, periodStreak), periodPR);
            if (FirstValidValue <= 1)
            {
                return;
            }

            ConsecDaysDown cdd    = ConsecDaysDown.Series(ds, 0);
            ConsecDaysUp   cdu    = ConsecDaysUp.Series(ds, 0);
            DataSeries     streak = new DataSeries(ds, "streak");

            for (int bar = 0; bar < ds.Count; bar++)
            {
                streak[bar] = cdd[bar] > 0 ? -cdd[bar] : cdu[bar] > 0 ? cdu[bar] : 0;
            }

            RSI        rsi3       = RSI.Series(ds, periodRSI);
            RSI        rsiStreak  = RSI.Series(streak, periodStreak);
            ROC        ret        = ROC.Series(ds, 1);
            DataSeries pr         = PercentRank.Series(ret, periodPR) * 100.0;
            DataSeries connorsRSI = (rsi3 + rsiStreak + pr) / 3;

            for (int bar = base.FirstValidValue; bar < ds.Count; bar++)
            {
                base[bar] = connorsRSI[bar];
            }
        }
Exemplo n.º 3
0
        public DV2_Bounded(DataSeries ds, int period, string description)
            : base(ds, description)
        {
            base.FirstValidValue = period;

            for (int bar = FirstValidValue; bar < ds.Count; bar++)
            {
                base[bar] = PercentRank.Series(ds, period)[bar];
            }
        }
Exemplo n.º 4
0
        public static PercentRank Series(DataSeries ds, int period)
        {
            string description = string.Concat(new object[] { "PercentRank(", ds.Description, ",", period, ")" });

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

            PercentRank _PercentRank = new PercentRank(ds, period, description);

            ds.Cache[description] = _PercentRank;
            return(_PercentRank);
        }
Exemplo n.º 5
0
        /*
         *              The creation of the oscillator involves taking the arithmetic average of the percentage returns (or 1-day ROCs) over the last 5 days.
         *              A geometric average is created by simply adding 1 to the percentage returns and taking the product of this series over the last 5 days
         *              (the cumulative return).
         *              The geometric average is derived by subtracting 1 from the cumulative return.
         *              Then we subtract the arithmetic return from the geometric return to find the divergence.
         *              This divergence is smoothed twice using a 3-day average to create smooth signals (note that the raw divergence produces signals in the same direction).
         *              Finally this smoothed divergence is “bounded,” by taking the PERCENTRANK of the series going back 1-year.
         */

        public GAMDO(Bars bars, string description)
            : base(bars, description)
        {
            base.FirstValidValue = 252;
            int period = 5;

            DataSeries ArAvg         = Community.Indicators.FastSMA.Series(bars.Close / (bars.Close >> 1), period) - 1d;
            DataSeries GeomAvg       = GMA.Series(bars.Close / (bars.Close >> 1), period) - 1d;
            DataSeries Diver         = GeomAvg - ArAvg;
            DataSeries SmoothedDiver = Community.Indicators.FastSMA.Series(Diver, 3);

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                base[bar] = PercentRank.Series(SmoothedDiver, 252)[bar];
            }
        }
Exemplo n.º 6
0
        public UDIDSRI(DataSeries ds, int period, int power, int percentRankPeriod, int iteration, string description)
            : base(ds, description)
        {
            base.FirstValidValue = Math.Max(period, percentRankPeriod);

            DataSeries diff     = ds - (ds >> 1);
            DataSeries mov      = new DataSeries(ds, "mov(" + ds.Description + "," + period + "," + percentRankPeriod + ")");
            DataSeries movement = new DataSeries(ds, "movement(" + ds.Description + "," + period + "," + percentRankPeriod + ")");
            DataSeries r        = DataSeries.Abs(ds / (ds >> 1) - 1);

            int u_iteration = iteration == 1 ? 1 : 2;

            for (int bar = FirstValidValue; bar < ds.Count; bar++)
            {
                if (diff[bar] > 0)
                {
                    mov[bar] = 1;
                }

                if (diff[bar] < 0)
                {
                    mov[bar] = -1;
                }

                movement[bar] = mov[bar] * Math.Pow((1 + r[bar]), power);
            }

            DataSeries UDIDSRI_1st = Sum.Series(mov, period);

            UDIDSRI_1st = PercentRank.Series(UDIDSRI_1st, percentRankPeriod);

            DataSeries UDIDSRI_2nd = Sum.Series(movement, period);

            UDIDSRI_2nd = PercentRank.Series(UDIDSRI_2nd, percentRankPeriod);

            for (int bar = FirstValidValue; bar < ds.Count; bar++)
            {
                base[bar] = u_iteration == 1 ? UDIDSRI_1st[bar] : UDIDSRI_2nd[bar];
            }
        }
Exemplo n.º 7
0
        public DVI(DataSeries B, string description)
            : base(B, description)
        {
            base.FirstValidValue = 252;

            DataSeries C = B / Community.Indicators.FastSMA.Series(B, 3) - 1;
            DataSeries D = (Community.Indicators.FastSMA.Series(C, 5) + (Community.Indicators.FastSMA.Series(C, 100) / 10)) / 2;
            DataSeries E = Community.Indicators.FastSMA.Series(D, 5);
            DataSeries F = GreaterThan.Series(B, (B >> 1), 1, -1);
            DataSeries G = (Sum.Series(F, 10) + (Sum.Series(F, 100) / 10)) / 2;
            DataSeries H = Community.Indicators.FastSMA.Series(G, 2);
            // DVI [Magnitude]
            DataSeries I = PercentRank.Series(E, 252);
            // DVI [Stretch]
            DataSeries J   = PercentRank.Series(H, 252);
            DataSeries DVI = (0.8 * I) + (0.2 * J);

            for (int bar = base.FirstValidValue; bar < B.Count; bar++)
            {
                base[bar] = DVI[bar];
            }
        }
Exemplo n.º 8
0
        public DSR(Bars bars, int period, string description)
            : base(bars, description)
        {
            base.FirstValidValue = 252;
            List <double> lst    = new List <double>();
            DataSeries    rawDSR = new DataSeries(bars, "raw dsr(" + period + ")");

            for (int bar = period; bar < bars.Count; bar++)
            {
                lst.Clear();

                for (int i = bar; i > bar - period; i--)
                {
                    lst.Add(bars.High[i]); lst.Add(bars.Low[i]); lst.Add(bars.Close[i]);
                }

                //DSR differential=  average(  65th percentile (H,L,C, 20-days), 80th percentile  (H,L,C, 20-days)) –
                //average(  35th percentile (H,L,C, 20-days), 20th percentile  (H,L,C, 20-days))

                double dsrDiff = (percentile(lst, 65) + percentile(lst, 80) / 2) - (percentile(lst, 35) + percentile(lst, 20) / 2);

                //DSR raw=  DSR differential/(max(H,L,C, 20-days)-min(H,L,C, 20-days))

                double dsrRaw = dsrDiff / (Highest.Series(bars.High, period)[bar] - Lowest.Series(bars.Low, period)[bar]);
                rawDSR[bar] = dsrRaw;
            }

            //DSR= 252-day percentrank of ( 10-day sma of DSR raw )
            var rangePartitioner = Partitioner.Create(FirstValidValue, bars.Count);

            Parallel.ForEach(rangePartitioner, (range, loopState) =>
            {
                for (int bar = range.Item1; bar < range.Item2; bar++)
                {
                    base[bar] = PercentRank.Series(Community.Indicators.FastSMA.Series(rawDSR, 10), 252)[bar];
                }
            });
        }