コード例 #1
0
        public Rex(Bars bars, int period, ChoiceOfMA option, string description)
            : base(bars, description)
        {
            base.FirstValidValue = period;
            DataSeries TVB = (bars.Close - bars.Low) + (bars.Close - bars.Open) - (bars.High - bars.Close);
            //DataSeries TVB = 3 * bars.Close - (bars.Low + bars.Open + bars.High);

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

            Parallel.ForEach(rangePartitioner, (range, loopState) =>
            {
                for (int bar = range.Item1; bar < range.Item2; bar++)
                {
                    if (option == ChoiceOfMA.EMA)
                    {
                        base[bar] = EMA.Series(TVB, period, EMACalculation.Modern)[bar];
                    }
                    else
                    if (option == ChoiceOfMA.SMA)
                    {
                        base[bar] = Community.Indicators.FastSMA.Series(TVB, period)[bar];
                    }
                    else
                    if (option == ChoiceOfMA.WMA)
                    {
                        base[bar] = WMA.Series(TVB, period)[bar];
                    }
                    else
                    if (option == ChoiceOfMA.SMMA)
                    {
                        base[bar] = SMMA.Series(TVB, period)[bar];
                    }
                }
            });
        }
コード例 #2
0
ファイル: ShiftedMA.cs プロジェクト: ToniTsai/LeetCode
        public static ShiftedMA Series(DataSeries ds, int period, int shift, ChoiceOfMA option)
        {
            string description = string.Concat(new object[] { "ShiftedMA(", ds.Description, ",", period, ",", shift, ",", option, ")" });

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

            ShiftedMA _ShiftedMA = new ShiftedMA(ds, period, shift, option, description);

            ds.Cache[description] = _ShiftedMA;
            return(_ShiftedMA);
        }
コード例 #3
0
ファイル: Envelope.cs プロジェクト: ToniTsai/LeetCode
        public static EnvelopeUpper Series(DataSeries ds, int period, double pct, ChoiceOfMA ma)
        {
            string description = string.Concat(new object[] { "MA Envelope Upper(", ds.Description, ",", period, ",", pct, ",", ma, ")" });

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

            EnvelopeUpper _EnvelopeUpper = new EnvelopeUpper(ds, period, pct, ma, description);

            ds.Cache[description] = _EnvelopeUpper;
            return(_EnvelopeUpper);
        }
コード例 #4
0
        public static Rex Series(Bars bars, int period, ChoiceOfMA option)
        {
            string description = string.Concat(new object[] { "Rex(", period, ",", option, ")" });

            if (bars.Cache.ContainsKey(description))
            {
                return((Rex)bars.Cache[description]);
            }

            Rex _Rex = new Rex(bars, period, option, description);

            bars.Cache[description] = _Rex;
            return(_Rex);
        }
コード例 #5
0
ファイル: Envelope.cs プロジェクト: ToniTsai/LeetCode
        public EnvelopeLower(DataSeries ds, int period, double pct, ChoiceOfMA ma, string description)
            : base(ds, description)
        {
            if (ma == ChoiceOfMA.SMA)
            {
                base.FirstValidValue = period;
            }
            else
            {
                base.FirstValidValue = (period * 3);
            }

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

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

            Parallel.ForEach(rangePartitioner, (range, loopState) =>
            {
                for (int bar = range.Item1; bar < range.Item2; bar++)
                {
                    if (ma == ChoiceOfMA.EMA)
                    {
                        base[bar] = EMA.Series(ds, period, EMACalculation.Modern)[bar] * (1 - (pct / 100));
                    }
                    else
                    if (ma == ChoiceOfMA.SMA)
                    {
                        base[bar] = Community.Indicators.FastSMA.Series(ds, period)[bar] * (1 - (pct / 100));
                    }
                    else
                    if (ma == ChoiceOfMA.WMA)
                    {
                        base[bar] = WMA.Series(ds, period)[bar] * (1 - (pct / 100));
                    }
                    else
                    if (ma == ChoiceOfMA.SMMA)
                    {
                        base[bar] = SMMA.Series(ds, period)[bar] * (1 - (pct / 100));
                    }
                }
            });
        }
コード例 #6
0
ファイル: ShiftedMA.cs プロジェクト: ToniTsai/LeetCode
        public ShiftedMA(DataSeries ds, int period, int shift, ChoiceOfMA option, string description)
            : base(ds, description)
        {
            if (ds.Count < period + shift)
            {
                return;
            }

            if (option == ChoiceOfMA.SMA)
            {
                base.FirstValidValue = period + shift;
            }
            else
            {
                base.FirstValidValue = (period * 3) + shift;
            }

            for (int bar = FirstValidValue; bar < ds.Count; bar++)
            {
                if (option == ChoiceOfMA.EMA)
                {
                    base[bar] = EMA.Series(ds, period, EMACalculation.Modern)[bar - shift];
                }
                else
                if (option == ChoiceOfMA.SMA)
                {
                    base[bar] = Community.Indicators.FastSMA.Series(ds, period)[bar - shift];
                }
                else
                if (option == ChoiceOfMA.WMA)
                {
                    base[bar] = WMA.Series(ds, period)[bar - shift];
                }
                else
                if (option == ChoiceOfMA.SMMA)
                {
                    base[bar] = SMMA.Series(ds, period)[bar - shift];
                }
            }
        }