public static List <decimal?> PivotLow(this IEnumerable <ICandle> candles, int?barsLeft, int?barsRight, bool?fillNullValues) { barsLeft = barsLeft ?? 4; barsRight = barsRight ?? 2; fillNullValues = fillNullValues ?? false; IIndicatorOptions options = new PivotLowOptions(barsLeft.Value, barsRight.Value, fillNullValues.Value); PivotLow pivotLow = new PivotLow(); return(pivotLow.Get(candles, options)); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { PivotLowOptions config = options != null ? (PivotLowOptions)options.Options : new PivotLowOptions(4, 2, false); List <decimal?> result = new List <decimal?>(); for (int i = 0; i < source.Count(); i++) { if (i < config.BarsLeft + config.BarsRight) { result.Add(null); continue; } bool isPivot = true; List <ICandle> subSet = source.Skip(i - config.BarsLeft - config.BarsRight).Take(config.BarsLeft + config.BarsRight + 1).ToList(); ICandle valueToCheck = subSet[config.BarsLeft]; // Check if the [barsLeft] bars left of what we're checking all have lower highs or equal for (int leftPivot = 0; leftPivot < config.BarsLeft; leftPivot++) { if (subSet[leftPivot].Low < valueToCheck.Low) { isPivot = false; break; } } // If it's still a pivot by this point, carry on checking the right side... if (isPivot) { // If the [barsRight] right side all have lower highs, it's a pivot! for (int rightPivot = config.BarsLeft + 1; rightPivot < subSet.Count; rightPivot++) { if (subSet[rightPivot].Low <= valueToCheck.Low) { isPivot = false; break; } } // If it's a pivot if (isPivot) { result.Add(valueToCheck.Low); } else { result.Add(null); } } else { result.Add(null); } } if (config.FillNullValues) { return(FillPivotNulls(result)); } return(result); }