/* 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; } }); }
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)); } }
public DyMoI(Bars bars, string description) : base(bars, description) { base.FirstValidValue = 14 * 3; // RSI is being used: an 'unstable' indicator StdDev SD5 = StdDev.Series(bars.Close, 5, StdDevCalculation.Population); DataSeries VIX = SD5 / Community.Indicators.FastSMA.Series(SD5, 10); for (int bar = FirstValidValue; bar < bars.Count; bar++) { int per = (int)(14 / VIX[bar]); base[bar] = per > 0 ? RSI.Series(bars.Close, per)[bar] : 50; } }
public DevStops(Bars bars, int period, double trFactor, double sdFactor, string description) : base(bars, description) { TR2DSeries tr2d = TR2DSeries.Series(bars); this.FirstValidValue = period; DataSeries avg = Community.Indicators.FastSMA.Series(tr2d, period * 2); StdDev sd = StdDev.Series(tr2d, period * 2, StdDevCalculation.Sample); for (int bar = FirstValidValue; bar < bars.Count; bar++) { base[bar] = trFactor * avg[bar] + sdFactor * sd[bar]; } }
public CTI(Bars bars, DataSeries ds, int period, bool positiveOnly, string description) : base(ds, description) { Helper.CompatibilityCheck(); base.FirstValidValue = period; if (FirstValidValue > ds.Count || FirstValidValue < 0) { FirstValidValue = ds.Count; } if (ds.Count < period) { return; } #region Parallelization (removed in 2018.08 for crash/hang issues) //var rangePartitioner = Partitioner.Create(FirstValidValue, ds.Count); //var rangePartitioner = Partitioner.Create(0, ds.Count); //Parallel.ForEach(rangePartitioner, (range, loopState) => //{ // for (int i = range.Item1; i < range.Item2; i++) // { // base[i] = LNRet.Series(bars, ds, period)[i] / (StdDev.Series(LNRet.Series(bars, ds, 1), period, StdDevCalculation.Sample)[i] * Math.Sqrt(period)); // if (positiveOnly) // base[i] = Math.Abs(base[i]); // } //}); #endregion for (int i = 0; i < ds.Count; i++) { base[i] = LNRet.Series(bars, ds, period)[i] / (StdDev.Series(LNRet.Series(bars, ds, 1), period, StdDevCalculation.Sample)[i] * Math.Sqrt(period)); if (positiveOnly) { base[i] = Math.Abs(base[i]); } } }
//populate public override void Populate() { TimeSeries ds = Parameters[0].AsTimeSeries; Int32 period = Parameters[1].AsInt; DateTimes = ds.DateTimes; if (period <= 0 || ds.Count == 0) { return; } var sma = SMA.Series(ds, period); StdDev sd = StdDev.Series(ds, period); TimeSeries zScore = (ds - sma) / sd; for (int bar = 0; bar < ds.Count; bar++) { Values[bar] = zScore[bar]; } }
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); } }
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]; } }
public InSyncIndex(Bars bars, string description) : base(bars, description) { base.FirstValidValue = 20; if (bars.Count < 20) { return; } DataSeries BOLInSLB = StdDev.Series(bars.Close, 20, StdDevCalculation.Sample) * 2; BOLInSLB = Community.Indicators.FastSMA.Series(bars.Close, 20) - BOLInSLB; DataSeries BOLInSUB = StdDev.Series(bars.Close, 20, StdDevCalculation.Sample) * 2; BOLInSUB = Community.Indicators.FastSMA.Series(bars.Close, 20) + BOLInSUB; DataSeries BOLInS2 = BOLInSUB - BOLInSLB; BOLInS2 = (bars.Close - BOLInSLB) / BOLInS2; EMV emv = EMV.Series(bars, 13); DataSeries EMVSer = Community.Indicators.FastSMA.Series(emv, 10); DataSeries EMVInS2 = EMVSer - Community.Indicators.FastSMA.Series(EMVSer, 10); DataSeries MACDSer = Community.Indicators.FastSMA.Series(MACD.Series(bars.Close), 10); DataSeries MACDInS2 = MACD.Series(bars.Close) - MACDSer; int Period = 18; DataSeries DPOSeries = bars.Close - (Community.Indicators.FastSMA.Series(bars.Close, Period) >> ((Period / 2) + 1)); DataSeries PDOSer = Community.Indicators.FastSMA.Series(DPOSeries, 10); DataSeries PDOInS2 = DPOSeries - PDOSer; DataSeries ROCSer = EMA.Series(ROC.Series(bars.Close, 10), 10, EMACalculation.Modern); DataSeries ROCInS2 = ROC.Series(bars.Close, 10) - ROCSer; DataSeries BOLInSLL = bars.Close * 0; DataSeries CCInS = bars.Close * 0; DataSeries EMVInSB = bars.Close * 0; DataSeries EMVInSS = bars.Close * 0; DataSeries MACDInSB = bars.Close * 0; DataSeries MACDInSS = bars.Close * 0; DataSeries MFIInS = bars.Close * 0; DataSeries PDOInSB = bars.Close * 0; DataSeries PDOInSS = bars.Close * 0; DataSeries ROCInSB = bars.Close * 0; DataSeries ROCInSS = bars.Close * 0; DataSeries RSIInS = bars.Close * 0; DataSeries STODInS = bars.Close * 0; DataSeries STOKInS = bars.Close * 0; for (int bar = base.FirstValidValue; bar < bars.Count; bar++) { if (BOLInS2[bar] < 0.05) { BOLInSLL[bar] = -5; } else if (BOLInS2[bar] > 0.95) { BOLInSLL[bar] = +5; } if (CCI.Series(bars, 14)[bar] > +100) { CCInS[bar] = +5; } else if (CCI.Series(bars, 14)[bar] < -100) { CCInS[bar] = -5; } if ((EMVInS2[bar] < 0) & (EMVSer[bar] < 0)) { EMVInSB[bar] = -5; } if ((EMVInS2[bar] > 0) & (EMVSer[bar] > 0)) { EMVInSS[bar] = +5; } if ((MACDInS2[bar] < 0) & (MACDSer[bar] < 0)) { MACDInSB[bar] = -5; } if ((MACDInS2[bar] > 0) & (MACDSer[bar] > 0)) { MACDInSS[bar] = +5; } if (MFI.Series(bars, 20)[bar] > 80) { MFIInS[bar] = +5; } else if (MFI.Series(bars, 20)[bar] < 20) { MFIInS[bar] = -5; } if ((PDOInS2[bar] < 0) & (PDOSer[bar] < 0)) { PDOInSB[bar] = -5; } if ((PDOInS2[bar] > 0) & (PDOSer[bar] > 0)) { PDOInSS[bar] = +5; } if ((ROCInS2[bar] < 0) & (ROCSer[bar] < 0)) { ROCInSB[bar] = -5; } if ((ROCInS2[bar] > 0) & (ROCSer[bar] > 0)) { ROCInSS[bar] = +5; } if (RSI.Series(bars.Close, 14)[bar] > 70) { RSIInS[bar] = +5; } else if (RSI.Series(bars.Close, 14)[bar] < 30) { RSIInS[bar] = -5; } if (StochD.Series(bars, 14, 3)[bar] > 80) { STODInS[bar] = +5; } else if (StochD.Series(bars, 14, 3)[bar] < 20) { STODInS[bar] = -5; } if (StochK.Series(bars, 14)[bar] > 80) { STOKInS[bar] = +5; } else if (StochK.Series(bars, 14)[bar] < 20) { STOKInS[bar] = -5; } base[bar] = 50 + CCInS[bar] + BOLInSLL[bar] + RSIInS[bar] + STODInS[bar] + MFIInS[bar] + EMVInSB[bar] + EMVInSS[bar] + ROCInSS[bar] + ROCInSB[bar] + STOKInS[bar] + MACDInSS[bar] + MACDInSB[bar] + PDOInSS[bar - 10] + PDOInSB[bar - 10]; } }