public Coppock(DataSeries ds, int ROCPeriod1, int ROCPeriod2, int MAPeriod, CoppockCalculation option, string description) : base(ds, description) { base.FirstValidValue = Math.Max(MAPeriod, Math.Max(ROCPeriod1, ROCPeriod2)); if (FirstValidValue > ds.Count || FirstValidValue < 0) { FirstValidValue = ds.Count; } if (ds.Count < Math.Max(ROCPeriod1, ROCPeriod2)) { return; } DataSeries Coppock = WMA.Series((ROC.Series(ds, ROCPeriod1) + ROC.Series(ds, ROCPeriod2)), MAPeriod); DataSeries Coppock2 = WMA.Series((Community.Indicators.FastSMA.Series(ds, 22) / Community.Indicators.FastSMA.Series(ds >> 250, 22) - 1), 150); for (int bar = FirstValidValue; bar < ds.Count; bar++) { if (option == CoppockCalculation.Option1) { base[bar] = Coppock[bar]; } else { base[bar] = Coppock2[bar]; } } }
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]; } } }); }
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)); } } }); }
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; } }
public HullMA(DataSeries ds, int period, string description) : base(ds, description) { base.FirstValidValue = period; if (ds.Count < period) { return; } WMA SlowWMA = WMA.Series(ds, period); WMA FastWMA = WMA.Series(ds, (int)(period / 2)); DataSeries hma = WMA.Series((FastWMA + (FastWMA - SlowWMA)), (int)Math.Sqrt(period)); for (int bar = period; bar < ds.Count; bar++) { base[bar] = hma[bar]; } }
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]; } } }
public KaseCD(Bars bars, int fastPeriod, int slowPeriod, string description) : base(bars, description) { base.FirstValidValue = Math.Max(fastPeriod, slowPeriod); DataSeries RWH = new DataSeries(bars, "RWH"); DataSeries RWL = new DataSeries(bars, "RWL"); for (int bar = FirstValidValue; bar < bars.Count; bar++) { RWH[bar] = (((bars.High[bar] - bars.Low[bar - slowPeriod])) / ((ATR.Series(bars, slowPeriod)[bar] * Math.Sqrt(slowPeriod)))); RWL[bar] = (((bars.High[bar - slowPeriod] - bars.Low[bar])) / ((ATR.Series(bars, slowPeriod)[bar] * Math.Sqrt(slowPeriod)))); } DataSeries Pk = Community.Indicators.FastSMA.Series(WMA.Series((RWH - RWL), fastPeriod), fastPeriod); DataSeries KCD = Pk - Community.Indicators.FastSMA.Series(Pk, slowPeriod); for (int bar = FirstValidValue; bar < bars.Count; bar++) { base[bar] = KCD[bar]; } }