StockSharp/StockSharp · error · ArgumentOutOfRangeException

Specified argument was out of the range of valid values. (Pa

Error message

Specified argument was out of the range of valid values. (Parameter 'parameters')

What it means

GpuPriceChannelsCalculator.Calculate throws ArgumentOutOfRangeException on the 'parameters' guard when the parameters array is empty (Length == 0). The calculator cannot dispatch any GPU kernel without at least one parameter set, so it rejects the call at the public API boundary before allocating buffers or loading kernels.

Source

Thrown at Algo.Gpu/Indicators/GpuPriceChannelsCalculator.cs:149

	{
		_kernel = Accelerator.LoadAutoGroupedStreamKernel
			<Index3D, ArrayView<GpuCandle>, ArrayView<GpuPriceChannelsResult>, ArrayView<int>, ArrayView<int>, ArrayView<GpuPriceChannelsParams>>(PriceChannelsKernel);
	}

	/// <inheritdoc />
	public override GpuPriceChannelsResult[][][] Calculate(GpuCandle[][] candlesSeries, GpuPriceChannelsParams[] parameters)
	{
		ArgumentNullException.ThrowIfNull(candlesSeries);
		ArgumentNullException.ThrowIfNull(parameters);

		if (candlesSeries.Length == 0)
		{
			throw new ArgumentOutOfRangeException(nameof(candlesSeries));
		}

		if (parameters.Length == 0)
		{
			throw new ArgumentOutOfRangeException(nameof(parameters));
		}

		var seriesCount = candlesSeries.Length;

		var totalSize = 0;
		var seriesOffsets = new int[seriesCount];
		var seriesLengths = new int[seriesCount];

		for (var s = 0; s < seriesCount; s++)
		{
			seriesOffsets[s] = totalSize;
			var len = candlesSeries[s]?.Length ?? 0;
			seriesLengths[s] = len;
			totalSize += len;
		}

		var flatCandles = new GpuCandle[totalSize];
		var maxLen = 0;

View on GitHub (pinned to 601a191de6)

Solutions

  1. Ensure the GpuPriceChannelsParams[] passed to Calculate contains at least one element before invoking.
  2. If the caller legitimately has zero parameters, short-circuit and return an empty result instead of calling the GPU calculator.
  3. Add a unit test asserting Calculate throws on an empty parameters array so the contract is locked.

Example fix

// before
calc.Calculate(series, Array.Empty<GpuPriceChannelsParams>());
// after
if (parameters.Length == 0) return Array.Empty<GpuPriceChannelsResult[][]>();
calc.Calculate(series, parameters);
Defensive patterns

Strategy: validation

Validate before calling

if (candlesSeries is null || candlesSeries.Length == 0) return Array.Empty<GpuPriceChannelsResult[][]>();
if (parameters is null || parameters.Length == 0) return Array.Empty<GpuPriceChannelsResult[][]>();

Type guard

static bool HasParameters<T>(T[] parameters) => parameters is { Length: > 0 };

Prevention

When it happens

Trigger: Calling Calculate(candlesSeries, new GpuPriceChannelsParams[0]) or Calculate(candlesSeries, Array.Empty<GpuPriceChannelsParams>()). Also triggered when a caller builds the parameters array from a filter/loop that yields zero elements.

Common situations: A batch-optimization loop filters parameters down to none; a config/UI passes an empty parameter list because no indicator period was selected; a default-initialized array was never populated before the call.

Related errors


AI-assisted analysis of StockSharp/StockSharp@601a191de6 (2026-08-13). Data as JSON: /api/errors/2bba0520453f59df. Report an issue: GitHub.