Esempio n. 1
0
        public Density(Bars bars, int NBars, string description)
            : base(bars, description)
        {
            base.FirstValidValue = NBars;

            DataSeries Area = (Highest.Series(bars.High, NBars) - Lowest.Series(bars.Low, NBars));

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                base[bar] = Sum.Series(TrueRange.Series(bars), NBars)[bar] / Area[bar];
            }
        }
Esempio n. 2
0
        public Choppiness(Bars bars, int period, string description)
            : base(bars, description)
        {
            base.FirstValidValue = period;

            double     true_high, true_low, true_rng, sum;
            DataSeries n_high = bars.High - bars.High;
            DataSeries n_low  = bars.Low - bars.Low;

            for (int bar = bars.FirstActualBar + period; bar < bars.Count; bar++)
            {
                true_high   = Math.Max(bars.High[bar], bars.Close[bar - 1]);
                true_low    = Math.Min(bars.Low[bar], bars.Close[bar - 1]);
                true_rng    = TrueRange.Series(bars)[bar];
                n_high[bar] = true_high;
                n_low[bar]  = true_low;
            }

            DataSeries trueHigh = Highest2.Series(bars.High, bars.Close >> 1, period);
            DataSeries trueLow  = Lowest2.Series(bars.Low, bars.Close >> 1, period);

            double nHigh, nLow, nRange, ratio, log_ratio, log_n;

            for (int bar = bars.FirstActualBar + period; bar < bars.Count; bar++)
            {
                // OLD:

                /* nHigh = Highest.Series( n_high, period )[bar];
                 * nLow = Lowest.Series( n_low, period )[bar]; */

                // NEW:
                nHigh = trueHigh[bar];
                nLow  = trueLow[bar];

                nRange    = nHigh - nLow;
                sum       = Sum.Series(TrueRange.Series(bars), period)[bar];
                ratio     = sum / nRange;
                log_ratio = Math.Log(ratio);
                log_n     = Math.Log(period);

                if (bar <= period)
                {
                    base[bar] = 50;
                }
                else
                {
                    base[bar] = 100 * log_ratio / log_n;
                }
            }
        }
Esempio n. 3
0
        public TrendQuality(Bars bars, int period, string description)
            : base(bars, description)
        {
            base.FirstValidValue = period;
            double val = 0.0; double net = 0.0; double gross = 0.0;

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                net       = Momentum.Series(bars.Close, period)[bar];
                gross     = Sum.Series(TrueRange.Series(bars), period)[bar];
                val       = (gross > 0) ? (net / gross) * 100 : 0;
                base[bar] = val;
            }
        }
Esempio n. 4
0
        public NRTR_WATR(Bars bars, int lookback, double multiple, string description)
            : base(bars, description)
        {
            base.FirstValidValue = lookback;

            int    Trend   = 0;
            double Reverse = 0;
            double HPrice  = 0;
            double LPrice  = 0;

            DataSeries K = WMA.Series(TrueRange.Series(bars), lookback) * multiple;

            for (int bar = base.FirstValidValue; bar < bars.Count; bar++)
            {
                // Calculate the NRTR_WATR Series
                if (Trend >= 0)
                {
                    HPrice  = Math.Max(bars.Close[bar], HPrice);
                    Reverse = HPrice - K[bar];

                    if (bars.Close[bar] <= Reverse)
                    {
                        Trend   = -1;
                        LPrice  = bars.Close[bar];
                        Reverse = LPrice + K[bar];
                    }
                }
                if (Trend <= 0)
                {
                    LPrice  = Math.Min(bars.Close[bar], LPrice);
                    Reverse = LPrice + K[bar];

                    if (bars.Close[bar] >= Reverse)
                    {
                        Trend   = 1;
                        HPrice  = bars.Close[bar];
                        Reverse = HPrice - K[bar];
                    }
                }

                base[bar] = Reverse;
            }
        }