//Constructor public PivotPointBar(Bars bars, int period, bool pivotPointHigh, bool tradeable, string description) : base(bars, description) { _bars = bars; _ppHigh = pivotPointHigh; _period = period; _tradeable = tradeable; FirstValidValue += _period; if (bars.Count < _period) { return; } for (int bar = _period; bar < bars.Count; bar++) { this[bar] = -1d; // returns -1 until a Valid Pivot Point is found } for (int bar = _period; bar < bars.Count; bar++) { if (_tradeable) { if (_ppHigh) { if (bars.High[bar] >= Highest.Series(bars.High, _period)[bar - 1]) { _lastPP = bar; } } else if (bars.Low[bar] <= Lowest.Series(bars.Low, _period)[bar - 1]) { _lastPP = bar; } } else { int periodFwd = _period; if (bar + period >= bars.Count) { periodFwd = bars.Count - bar - 1; } if (_ppHigh) { if (bars.High[bar] >= Highest.Series(bars.High, _period)[bar - 1] && bars.High[bar] >= Highest.Value(bar + periodFwd, bars.High, periodFwd)) // use Value method since periodFwd is variable at the end { _lastPP = bar; } } else if (bars.Low[bar] <= Lowest.Series(bars.Low, _period)[bar - 1] && bars.Low[bar] <= Lowest.Value(bar + periodFwd, bars.Low, periodFwd)) { _lastPP = bar; } } this[bar] = _lastPP; } }
public override void CalculatePartialValue() { if (_bars.Count < _period || _bars.Low.PartialValue == Double.NaN || _bars.High.PartialValue == Double.NaN) { PartialValue = Double.NaN; return; } int bar = _bars.Count; // bar - 1 is last bar number (prior to PartialBar) if (_tradeable) { if (_ppHigh) { if (_bars.High.PartialValue >= Highest.Series(_bars.High, _period)[bar - 1]) { _lastPP = bar; } } else if (_bars.Low.PartialValue <= Lowest.Series(_bars.Low, _period)[bar - 1]) { _lastPP = bar; } } else { int periodFwd = _period; if (bar + _period >= _bars.Count) { periodFwd = _bars.Count - bar - 1; } if (_ppHigh) { if (_bars.High.PartialValue >= Highest.Series(_bars.High, _period)[bar - 1] && _bars.High.PartialValue >= Highest.Value(bar + periodFwd, _bars.High, periodFwd)) // use Value method since periodFwd is variable at the end { _lastPP = bar; } } else if (_bars.Low.PartialValue <= Lowest.Series(_bars.Low, _period)[bar - 1] && _bars.Low.PartialValue <= Lowest.Value(bar + periodFwd, _bars.Low, periodFwd)) { _lastPP = bar; } } this.PartialValue = _lastPP; }
protected override void Execute() { const string sep = ","; const string fmt = "0.00########"; string dateFormat = "yyyyMMdd"; string workingDir = @"Z:\Win10D"; int barsInAYear = 250; ClearDebug(); string today = DateTime.Now.ToString("yyyy-MM-dd"); string path = Path.Combine(workingDir, "Data", today); PrintDebug(String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", "Symbol", "HighPrice", "LowPrice", "PriceDiffPct", "Weeks", "PriceDiffPctWk")); for (int ds = 0; ds < DataSetSymbols.Count; ds++) { string symbol = DataSetSymbols[ds]; Bars bars = GetExternalSymbol(symbol, false); PrintStatusBar("Processing: " + ds + " / " + DataSetSymbols.Count + " : " + bars.Symbol + " "); if (bars.Count & gt; barsInAYear) { double highPrice = Highest.Value(bars.Count - 1, bars.High, barsInAYear); double highBar = HighestBar.Value(bars.Count - 1, bars.High, barsInAYear); double lowPrice = Lowest.Value(bars.Count - 1, bars.Low, barsInAYear); double lowBar = LowestBar.Value(bars.Count - 1, bars.Low, barsInAYear); if (highBar & gt; lowBar) { double priceDiffPct = (highPrice - lowPrice) / lowPrice * 100; double weeks = Math.Ceiling((highBar - lowBar) / 5.0); double priceDiffPctWk = priceDiffPct / weeks; PrintDebug(String.Format("{0}\t{1:f}\t{2:f}\t{3:f}\t{4}\t{5:f}", symbol, highPrice, lowPrice, priceDiffPct, weeks, priceDiffPctWk)); } } Bars.Cache.Clear(); } //PrintStatusBar("Complete!"); }