StockSharp/StockSharp · error · ArgumentOutOfRangeException

candlesSeries

Error message

candlesSeries

What it means

GpuMomentumOfMovingAverageCalculator.Calculate throws ArgumentOutOfRangeException(paramName="candlesSeries") when the GpuCandle[][] array is empty. The pipeline flattens series, allocates device buffers (including an RoR float scratch buffer), and launches MomentumParamsSeriesKernel over (series x parameters); zero series makes the extent degenerate, so the guard rejects it.

Source

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

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

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

		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. Guard the caller: `if (candlesSeries.Length == 0) return Array.Empty<GpuIndicatorResult[][]>();`.
  2. Ensure the data feed populated at least one series.
  3. Short-circuit at the batch boundary when seriesCount is zero.

Example fix

// before
calc.Calculate(seriesArray, parameters);

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

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Calling Calculate with an empty series array from a batch aggregator that matched no instruments.

Common situations: No candles for the batch window; a symbol filter removing all series; an empty data-feed response forwarded to the GPU stage.

Related errors


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