{"record":{"id":"d870d4b9d56749a1","repo":"StockSharp/StockSharp","slug":"parameters-d870d4","errorCode":null,"errorMessage":"parameters","messagePattern":"parameters","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Algo.Gpu/Indicators/GpuKamaCalculator.cs","lineNumber":78,"sourceCode":"\t/// <param name=\"context\">ILGPU context.</param>\n\t/// <param name=\"accelerator\">ILGPU accelerator.</param>\n\tpublic GpuKamaCalculator(Context context, Accelerator accelerator)\n\t\t: base(context, accelerator)\n\t{\n\t\t_kernel = Accelerator.LoadAutoGroupedStreamKernel\n\t\t\t<Index2D, ArrayView<GpuCandle>, ArrayView<GpuIndicatorResult>, ArrayView<int>, ArrayView<int>, ArrayView<GpuKamaParams>>(KamaParamsSeriesKernel);\n\t}\n\n\t/// <inheritdoc />\n\tpublic override GpuIndicatorResult[][][] Calculate(GpuCandle[][] candlesSeries, GpuKamaParams[] 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\t\tif (parameters.Length == 0)\n\t\t\tthrow new ArgumentOutOfRangeException(nameof(parameters));\n\n\t\tvar seriesCount = candlesSeries.Length;\n\n\t\t// Flatten input\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\n\t\tvar flatCandles = new GpuCandle[totalSize];\n\t\tvar offset = 0;","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/StockSharp/StockSharp/blob/601a191de678bff83da28b14828f8885214ca71c/Algo.Gpu/Indicators/GpuKamaCalculator.cs#L60-L96","documentation":"The Kaufman Adaptive Moving Average (KAMA) GPU calculator's Calculate method throws ArgumentOutOfRangeException(nameof(parameters)) when the GpuKamaParams[] array has zero elements. The kernel grid extent is constructed as Index2D(parameters.Length, seriesCount), so a zero-length parameters array creates a degenerate grid. Additionally the output buffer size equals totalSize * parameters.Length, which would be zero — making the entire computation meaningless. The guard fires before any GPU allocation.","triggerScenarios":"Calling Kaufman Adaptive Moving Average (KAMA)Calculator.Calculate(candlesSeries, Array.Empty<GpuKamaParams>()) or passing new GpuKamaParams[0]. Also occurs when parameters originate from a parameter-sweep or configuration builder that yields zero entries (e.g., a deserialized config has an empty parameters array, or a sweep filter removed all candidate sets).","commonSituations":"Configuration file or JSON payload defines the indicator but leaves its parameters array empty or omitted. A parameter-optimization sweep filtered out all candidates by a constraint (e.g., min/max period bounds). Default-parameters fallback returned an empty array due to a missing or misconfigured defaults provider. A UI or CLI layer did not populate parameter sets before dispatching the batch calculation.","solutions":["Inspect the GpuKamaParams[] source before the call — log parameters.Length to confirm whether the array is genuinely empty or never populated.","Ensure at least one parameter set exists: if the application requires a default, seed parameters with the indicator's canonical default {params_type} instance.","Guard the caller: if parameters is null or has zero length, skip or short-circuit before calling Calculate.","Check the configuration/deserialization pipeline — verify the JSON/YAML schema maps parameters correctly and the array is not silently omitted or mapped to a null/empty default."],"exampleFix":"// before\nvar results = calc.Calculate(candlesSeries, parameters); // parameters may be empty\n\n// after\nif (parameters is null || parameters.Length == 0)\n    parameters = new[] { new GpuKamaParams() }; // canonical default\nvar results = calc.Calculate(candlesSeries, parameters);","handlingStrategy":"validation","validationCode":"// Validate parameters before calling Calculate\nif (parameters is null || parameters.Length == 0)\n    throw new ArgumentException(\"At least one GpuKamaParams set is required.\", nameof(parameters));\n\nvar results = calc.Calculate(candlesSeries, parameters);","typeGuard":"static bool HasValidParameters(GpuKamaParams[] parameters)\n    => parameters is not null && parameters.Length > 0;\n\n// usage\nif (!HasValidParameters(parameters))\n    parameters = new[] { new GpuKamaParams() }; // apply default\nvar results = calc.Calculate(candlesSeries, parameters);","tryCatchPattern":"// Wrap if the empty-parameters 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 == \"parameters\")\n{\n    logger.LogWarning(\"No parameters provided for Kaufman Adaptive Moving Average (KAMA); applying default\");\n    var defaultParams = new[] { new GpuKamaParams() };\n    var results = calc.Calculate(candlesSeries, defaultParams);\n}","preventionTips":["Always ensure the parameters array contains at least one element before calling Calculate.","Seed configuration objects with a non-empty default parameter set so a missing config entry does not propagate an empty array.","In parameter-sweep pipelines, validate the filtered candidate set length before dispatching to the GPU calculator.","Add a deserialization validator or JSON schema constraint requiring a minimum array length of 1 for the parameters field."],"tags":["gpu","argument-validation","ilgpu","indicators","argumentoutofrange","finance-technical-analysis","parameters"],"backgroundTag":null,"analyzedSha":"601a191de678bff83da28b14828f8885214ca71c","analyzedAt":"2026-08-13T20:43:24.460Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}