StockSharp/StockSharp · error · ArgumentOutOfRangeException

nameof(candlesSeries)

Error message

nameof(candlesSeries)

What it means

GpuRelativeMomentumIndexCalculator.Calculate throws ArgumentOutOfRangeException on the 'candlesSeries' guard when the outer series array is empty (Length == 0). The RMI 3D kernel flattens series into contiguous buffers and needs at least one series; null inner series are tolerated.

Source

Thrown at Algo.Gpu/Indicators/GpuRelativeMomentumIndexCalculator.cs:69

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

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

		// Flatten input
		var totalSize = 0;
		var seriesOffsets = new int[seriesCount];
		var seriesLengths = new int[seriesCount];
		var maxLen = 0;

		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. Provide a candlesSeries array with at least one inner series.
  2. Skip the call and return empty results for an empty batch.
  3. Assert the loader returned at least one series before the GPU call.

Example fix

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

Strategy: validation

Validate before calling

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

Type guard

static bool HasSeries(GpuCandle[][] series) => series is { Length: > 0 };

Prevention

When it happens

Trigger: Calling Calculate(Array.Empty<GpuCandle[]>(), parameters) or Calculate(new GpuCandle[0][], parameters).

Common situations: Filtered symbol set is empty; no candle data for the window; test omitted data.

Related errors


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