// PIVOT POINTS /// <include file='./info.xml' path='indicator/*' /> /// public static IEnumerable <PivotPointsResult> GetPivotPoints <TQuote>( IEnumerable <TQuote> history, PeriodSize windowSize, PivotPointType pointType = PivotPointType.Standard) where TQuote : IQuote { // sort history List <TQuote> historyList = history.Sort(); // check parameter arguments ValidatePivotPoints(history, windowSize); // initialize List <PivotPointsResult> results = new List <PivotPointsResult>(historyList.Count); PivotPointsResult windowPoint = new PivotPointsResult(); TQuote h0 = historyList[0]; int windowId = GetWindowNumber(h0.Date, windowSize); int windowEval; bool firstWindow = true; decimal windowHigh = h0.High; decimal windowLow = h0.Low; decimal windowOpen = h0.Open; decimal windowClose = h0.Close; // roll through history for (int i = 0; i < historyList.Count; i++) { TQuote h = historyList[i]; PivotPointsResult r = new PivotPointsResult { Date = h.Date }; // new window evaluation windowEval = GetWindowNumber(h.Date, windowSize); if (windowEval != windowId) { windowId = windowEval; firstWindow = false; // set new levels if (pointType == PivotPointType.Woodie) { windowOpen = h.Open; } windowPoint = GetPivotPoint(pointType, windowOpen, windowHigh, windowLow, windowClose); // reset window min/max thresholds windowOpen = h.Open; windowHigh = h.High; windowLow = h.Low; } // add levels if (!firstWindow) { // pivot point r.PP = windowPoint.PP; // support r.S1 = windowPoint.S1; r.S2 = windowPoint.S2; r.S3 = windowPoint.S3; r.S4 = windowPoint.S4; // resistance r.R1 = windowPoint.R1; r.R2 = windowPoint.R2; r.R3 = windowPoint.R3; r.R4 = windowPoint.R4; } results.Add(r); // capture window threholds (for next iteration) windowHigh = (h.High > windowHigh) ? h.High : windowHigh; windowLow = (h.Low < windowLow) ? h.Low : windowLow; windowClose = h.Close; } return(results); }
// PIVOT POINTS /// <include file='./info.xml' path='indicator/*' /> /// public static IEnumerable <PivotPointsResult> GetRollingPivots <TQuote>( IEnumerable <TQuote> history, int windowPeriod, int offsetPeriod, PivotPointType pointType = PivotPointType.Standard) where TQuote : IQuote { // sort history List <TQuote> historyList = history.Sort(); // check parameter arguments ValidateRollingPivots(history, windowPeriod, offsetPeriod); // initialize List <PivotPointsResult> results = new(historyList.Count); // roll through history for (int i = 0; i < historyList.Count; i++) { TQuote h = historyList[i]; PivotPointsResult r = new() { Date = h.Date }; if (i >= windowPeriod + offsetPeriod) { // window values int s = i - windowPeriod - offsetPeriod; TQuote hi = historyList[s]; decimal windowHigh = hi.High; decimal windowLow = hi.Low; decimal windowClose = historyList[i - offsetPeriod - 1].Close; for (int p = s; p <= i - offsetPeriod - 1; p++) { TQuote d = historyList[p]; windowHigh = (d.High > windowHigh) ? d.High : windowHigh; windowLow = (d.Low < windowLow) ? d.Low : windowLow; } // pivot points PivotPointsResult wp = GetPivotPoint(pointType, h.Open, windowHigh, windowLow, windowClose); r.PP = wp.PP; r.S1 = wp.S1; r.S2 = wp.S2; r.S3 = wp.S3; r.S4 = wp.S4; r.R1 = wp.R1; r.R2 = wp.R2; r.R3 = wp.R3; r.R4 = wp.R4; } results.Add(r); } return(results); }