StockSharp/StockSharp · error · ArgumentOutOfRangeException

candlesSeries

Error message

candlesSeries

What it means

ArgumentOutOfRangeException with ParamName="candlesSeries", thrown by GpuLinearRegSlopeCalculator.Calculate at the empty-array guard (Algo.Gpu/Indicators/GpuLinearRegSlopeCalculator.cs:62). The linear-regression slope kernel is launched over an Index2D grid whose dimensions depend on the candle series count; an empty outer array gives a degenerate zero-length launch and an undefined result[][][] shape, so it is rejected up front.

Source

Thrown at Algo.Gpu/Indicators/GpuLinearRegSlopeCalculator.cs:62

	/// Initializes a new instance of the <see cref="GpuLinearRegSlopeCalculator"/> class.
	/// </summary>
	/// <param name="context">ILGPU context.</param>
	/// <param name="accelerator">ILGPU accelerator.</param>
	public GpuLinearRegSlopeCalculator(Context context, Accelerator accelerator)
	: base(context, accelerator)
	{
		_kernel = Accelerator.LoadAutoGroupedStreamKernel
			<Index2D, ArrayView<GpuCandle>, ArrayView<GpuIndicatorResult>, ArrayView<int>, ArrayView<int>, ArrayView<GpuLinearRegSlopeParams>>(LinearRegSlopeParamsSeriesKernel);
	}

	/// <inheritdoc />
	public override GpuIndicatorResult[][][] Calculate(GpuCandle[][] candlesSeries, GpuLinearRegSlopeParams[] 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;
		}

View on GitHub (pinned to 601a191de6)

Solutions

  1. Short-circuit the caller when candlesSeries is empty (return an empty/identity result instead of calling Calculate).
  2. Tighten the upstream filter so the batch always contains at least one series.
  3. Add a batch-boundary assertion that fails fast with a domain-specific message rather than relying on the GPU guard.

Example fix

// before
var results = calc.Calculate(candlesSeries, parameters);

// after
if (candlesSeries is null || candlesSeries.Length == 0)
    return Array.Empty<GpuIndicatorResult[][]>();
var results = calc.Calculate(candlesSeries, parameters);
Defensive patterns

Strategy: validation

Validate before calling

if (candlesSeries is null || candlesSeries.Length == 0)
    return Array.Empty<GpuIndicatorResult[][]>();
var results = calc.Calculate(candlesSeries, parameters);

Type guard

static bool IsValidSeries(GpuCandle[][] s) => s is not null && s.Length > 0;

Try / catch

try { var r = calc.Calculate(candlesSeries, parameters); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "candlesSeries")
{ /* empty batch: return empty result */ }

Prevention

When it happens

Trigger: Calling Calculate with candlesSeries.Length == 0 — an empty GpuCandle[][] produced by a filtering step that removed all series, or an explicit Array.Empty<GpuCandle[]>() payload.

Common situations: Symbol/date filters in a backtester that exclude everything; pipeline stages that pass through an empty batch without short-circuiting; empty-input edge-case tests.

Related errors


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