示例#1
0
        public static List <decimal?> PivotHigh(this IEnumerable <ICandle> candles, int?barsLeft, int?barsRight, bool?fillNullValues)
        {
            barsLeft       = barsLeft ?? 4;
            barsRight      = barsRight ?? 2;
            fillNullValues = fillNullValues ?? false;

            IIndicatorOptions options   = new PivotHighOptions(barsLeft.Value, barsRight.Value, fillNullValues.Value);
            PivotHigh         pivotHigh = new PivotHigh();

            return(pivotHigh.Get(candles, options));
        }
示例#2
0
        public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null)
        {
            PivotHighOptions config = options != null ? (PivotHighOptions)options.Options : new PivotHighOptions(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();
                var            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].High > valueToCheck.High)
                    {
                        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].High >= valueToCheck.High)
                        {
                            isPivot = false;
                            break;
                        }
                    }

                    // If it's a pivot
                    if (isPivot)
                    {
                        result.Add(valueToCheck.High);
                    }
                    else
                    {
                        result.Add(null);
                    }
                }
                else
                {
                    result.Add(null);
                }
            }

            if (config.FillNullValues)
            {
                return(FillPivotNulls(result));
            }

            return(result);
        }