{"record":{"id":"f0a7fef48e8f9356","repo":"StockSharp/StockSharp","slug":"candlesseries-f0a7fe","errorCode":null,"errorMessage":"candlesSeries","messagePattern":"candlesSeries","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Algo.Gpu/Indicators/GpuKeltnerChannelsCalculator.cs","lineNumber":152,"sourceCode":"\t/// <summary>\n\t/// Initializes a new instance of the <see cref=\"GpuKeltnerChannelsCalculator\"/> class.\n\t/// </summary>\n\t/// <param name=\"context\">ILGPU context.</param>\n\t/// <param name=\"accelerator\">ILGPU accelerator.</param>\n\tpublic GpuKeltnerChannelsCalculator(Context context, Accelerator accelerator)\n\t\t: base(context, accelerator)\n\t{\n\t\t_kernel = Accelerator.LoadAutoGroupedStreamKernel<Index2D, ArrayView<GpuCandle>, ArrayView<GpuKeltnerChannelsResult>, ArrayView<int>, ArrayView<int>, ArrayView<GpuKeltnerChannelsParams>>(KeltnerChannelsParamsSeriesKernel);\n\t}\n\n\t/// <inheritdoc />\n\tpublic override GpuKeltnerChannelsResult[][][] Calculate(GpuCandle[][] candlesSeries, GpuKeltnerChannelsParams[] parameters)\n\t{\n\t\tArgumentNullException.ThrowIfNull(candlesSeries);\n\t\tArgumentNullException.ThrowIfNull(parameters);\n\n\t\tif (candlesSeries.Length == 0)\n\t\t\tthrow new ArgumentOutOfRangeException(nameof(candlesSeries));\n\n\t\tif (parameters.Length == 0)\n\t\t\tthrow new ArgumentOutOfRangeException(nameof(parameters));\n\n\t\tvar seriesCount = candlesSeries.Length;\n\n\t\tvar totalSize = 0;\n\t\tvar seriesOffsets = new int[seriesCount];\n\t\tvar seriesLengths = new int[seriesCount];\n\n\t\tfor (var s = 0; s < seriesCount; s++)\n\t\t{\n\t\t\tseriesOffsets[s] = totalSize;\n\t\t\tvar len = candlesSeries[s]?.Length ?? 0;\n\t\t\tseriesLengths[s] = len;\n\t\t\ttotalSize += len;\n\t\t}\n","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/StockSharp/StockSharp/blob/601a191de678bff83da28b14828f8885214ca71c/Algo.Gpu/Indicators/GpuKeltnerChannelsCalculator.cs#L134-L170","documentation":"The Keltner Channels GPU calculator's Calculate method throws ArgumentOutOfRangeException(nameof(candlesSeries)) when the GpuCandle[][] jagged array passed as candlesSeries contains zero series. The method flattens every series into one contiguous GPU buffer and builds a kernel grid extent of Index2D(parameters.Length, seriesCount); an empty series array produces a degenerate zero-extent grid and a meaningless output buffer. The guard fires before any GPU allocation so no device resource is leaked.","triggerScenarios":"Calling Keltner ChannelsCalculator.Calculate(Array.Empty<GpuCandle[]>(), parameters) or passing a new GpuCandle[0][] as candlesSeries. Also triggered when candlesSeries is populated from a LINQ pipeline or data provider that yields zero elements (e.g., .Where(filter) eliminates all series, or a batch scheduler submits an empty work set).","commonSituations":"Market-data provider returned no bars for the requested symbol/timeframe (holiday, pre-market, or newly listed instrument). A volume or spread filter upstream stripped every series from the batch. A backtest engine iterating symbol groups hit an empty group. A configuration or scheduling layer defaulted candlesSeries to an empty collection instead of null.","solutions":["Inspect the data source feeding candlesSeries before the call — log candlesSeries.Length and each inner array's length to identify where the emptiness originates.","Guard the caller: if candlesSeries is null or has zero length, skip the Calculate call or return an empty result set rather than forwarding the empty array.","Verify upstream data loading: confirm the historical-data provider, database query, or CSV parser actually returned rows for every requested symbol.","If the empty case is valid (e.g., no trading data for a holiday), short-circuit early with an empty result array matching the expected return shape rather than calling Calculate."],"exampleFix":"// before\nvar results = calc.Calculate(candlesSeries, parameters); // candlesSeries may be empty\n\n// after\nif (candlesSeries is null || candlesSeries.Length == 0)\n    return Array.Empty<GpuIndicatorResult[][]>(); // or return the appropriately-shaped empty result\nvar results = calc.Calculate(candlesSeries, parameters);","handlingStrategy":"validation","validationCode":"// Validate before calling Calculate\nif (candlesSeries is null || candlesSeries.Length == 0)\n    throw new ArgumentException(\"candlesSeries must contain at least one series.\", nameof(candlesSeries));\n\n// Also verify each inner series is non-null and has data\nfor (var i = 0; i < candlesSeries.Length; i++)\n{\n    if (candlesSeries[i] is null || candlesSeries[i].Length == 0)\n        throw new ArgumentException($\"Series at index {i} is null or empty.\", nameof(candlesSeries));\n}\n\nvar results = calc.Calculate(candlesSeries, parameters);","typeGuard":"static bool IsValidCandlesSeries(GpuCandle[][] series)\n    => series is not null\n       && series.Length > 0\n       && series.All(s => s is not null && s.Length > 0);\n\n// usage\nif (!IsValidCandlesSeries(candlesSeries))\n    return EmptyResults();\nvar results = calc.Calculate(candlesSeries, parameters);","tryCatchPattern":"// Wrap only if the empty-array case is a recoverable runtime condition\ntry\n{\n    var results = calc.Calculate(candlesSeries, parameters);\n    // process results ...\n}\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"candlesSeries\")\n{\n    logger.LogWarning(\"No candle series provided for {Name}; skipping calculation\", nameof(calc));\n    return Array.Empty<GpuIndicatorResult[][]>();\n}","preventionTips":["Always check candlesSeries.Length > 0 before calling Calculate — the method does not accept empty arrays.","Log the source of each batch (symbol list, date range, provider name) so empty batches are traceable to their origin.","Use a data-provider wrapper that guarantees non-empty arrays or returns a sentinel/None instead of forwarding empties.","In backtest/batch loops, filter out symbols with insufficient historical data before building the candlesSeries array."],"tags":["gpu","argument-validation","ilgpu","indicators","argumentoutofrange","finance-technical-analysis","candle-data"],"backgroundTag":null,"analyzedSha":"601a191de678bff83da28b14828f8885214ca71c","analyzedAt":"2026-08-13T20:43:24.460Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}