public GannSwingOscillator(Bars bars, bool zero, string description) : base(bars, description) { bool SwingLo, SwingHi; base.FirstValidValue = 5; for (int bar = 5; bar < bars.Count; bar++) { SwingLo = (CumDown.Series(bars.Low, 1)[bar - 2] >= 2) && (CumUp.Series(bars.Low, 1)[bar] == 2); SwingHi = (CumUp.Series(bars.High, 1)[bar - 2] >= 2) && (CumDown.Series(bars.High, 1)[bar] == 2); if (SwingLo) { base[bar] = -1; } else if (SwingHi) { base[bar] = 1; } else // Behavior choice if (!zero) { base[bar] = this[bar - 1]; } else { base[bar] = 0; } } }
/// <summary> /// Parameterless Adaptive Lookback /// Determined as the distance between 2 last same-sign swings (last SwingHi to penultimate SwingHi and vice versa) /// </summary> /// <param name="bars">A Bars object</param> /// <param name="fastSwing">Use faster swing detection method</param> /// <param name="description">Series description</param> public AdaptiveLookback(Bars bars, bool fastSwing, string description) : base(bars, description) { bool SwingLo, SwingHi; double lastSL = bars.Low[1]; double lastSH = bars.High[1]; int swingCount = 0; double swingDirection = 0; List <Tuple <int, double> > lstSwingBars = new List <Tuple <int, double> >(); for (int bar = 5; bar < bars.Count; bar++) { SwingLo = (bars.Low[bar - 2] < bars.Low[bar - 3]) & (bars.Low[bar - 3] < bars.Low[bar - 4]) & (bars.Low[bar - 1] > bars.Low[bar - 2]) & (bars.Low[bar] > bars.Low[bar - 1]); SwingHi = (bars.High[bar - 2] > bars.High[bar - 3]) & (bars.High[bar - 3] > bars.High[bar - 4]) & (bars.High[bar - 1] < bars.High[bar - 2]) & (bars.High[bar] < bars.High[bar - 1]); if (fastSwing) { SwingLo = (CumDown.Series(bars.Low, 1)[bar - 2] >= 1) && (CumUp.Series(bars.High, 1)[bar] == 1); SwingHi = (CumUp.Series(bars.High, 1)[bar - 2] >= 1) && (CumDown.Series(bars.Low, 1)[bar] == 1); } swingDirection = SwingLo ? -1 : SwingHi ? 1 : 0; if ((swingDirection != 0) & (swingCount == 0)) { swingCount++; lstSwingBars.Add(new Tuple <int, double>(bar, swingDirection)); } else if (swingCount > 0) { if (swingDirection != 0.0) { swingCount++; double prevValue = lstSwingBars[lstSwingBars.Count - 1].Item1; if (prevValue != swingDirection) { lstSwingBars.Add(new Tuple <int, double>(bar, swingDirection)); } } if (swingCount == 3) { base.FirstValidValue = bar; } } if (lstSwingBars.Count >= 3) { int lastDistance = (int)(lstSwingBars[lstSwingBars.Count - 1].Item1 - lstSwingBars[lstSwingBars.Count - 2].Item1); int penultimateDistance = (int)(lstSwingBars[lstSwingBars.Count - 2].Item1 - lstSwingBars[lstSwingBars.Count - 3].Item1); int distanceBetweenTwo = (int)(lastDistance + penultimateDistance); base[bar] = distanceBetweenTwo; } } }
public NegativeCloses(DataSeries ds, int period, string description) : base(ds, description) { base.FirstValidValue = period; if (FirstValidValue > ds.Count || FirstValidValue < 0) { FirstValidValue = ds.Count; } if (ds.Count < period) { return; } DataSeries nc = new DataSeries(ds, "NegativeCloses(" + period + ")"); nc = CumDown.Series(ds, 1); nc /= nc; nc = Sum.Series(nc, period); for (int bar = period; bar < ds.Count; bar++) { base[bar] = nc[bar]; } }
public AdaptiveLookback(Bars bars, int howManySwings, bool UseAll, bool fastSwing, string description) : base(bars, description) { bool SwingLo, SwingHi; double lastSL = bars.Low[1]; double lastSH = bars.High[1]; int firstSwingBarOnChart = 0; int lastSwingInCalc = 0; int swingCount = 0; double so = 0; List <int> SwingBarArray = new List <int>(); for (int bar = 5; bar < bars.Count; bar++) { SwingLo = (bars.Low[bar - 2] < bars.Low[bar - 3]) & (bars.Low[bar - 3] < bars.Low[bar - 4]) & (bars.Low[bar - 1] > bars.Low[bar - 2]) & (bars.Low[bar] > bars.Low[bar - 1]); SwingHi = (bars.High[bar - 2] > bars.High[bar - 3]) & (bars.High[bar - 3] > bars.High[bar - 4]) & (bars.High[bar - 1] < bars.High[bar - 2]) & (bars.High[bar] < bars.High[bar - 1]); if (fastSwing) { SwingLo = (CumDown.Series(bars.Low, 1)[bar - 2] >= 1) && (CumUp.Series(bars.High, 1)[bar] == 1); SwingHi = (CumUp.Series(bars.High, 1)[bar - 2] >= 1) && (CumDown.Series(bars.Low, 1)[bar] == 1); } so = SwingLo ? -1 : SwingHi ? 1 : 0; if ((so != 0) & (swingCount == 0)) { firstSwingBarOnChart = bar; swingCount++; SwingBarArray.Add(bar); } else if (swingCount > 0) { if (so != 0.0) { swingCount++; SwingBarArray.Add(bar); } if (swingCount == howManySwings) { base.FirstValidValue = bar; } } lastSwingInCalc = (SwingBarArray.Count - howManySwings); if (lastSwingInCalc >= 0) { base[bar] = UseAll ? (int)(bars.Count / SwingBarArray.Count) : (bar - (int)SwingBarArray[lastSwingInCalc]) / howManySwings; } } }