StockSharp/StockSharp · error · ArgumentOutOfRangeException

candlesSeries

Error message

candlesSeries

What it means

GpuTemaCalculator.Calculate throws ArgumentOutOfRangeException(nameof(candlesSeries)) at line 62 when the GpuCandle[][] array is empty. TEMA (Triple EMA) needs candle series for its triple smoothing chain; zero series means no computation is meaningful. The guard precedes input flattening and ILGPU buffer allocation.

Source

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

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

	/// <inheritdoc />
	public override GpuIndicatorResult[][][] Calculate(GpuCandle[][] candlesSeries, GpuTemaParams[] 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. Pass at least one GpuCandle[] series.
  2. Short-circuit upstream when the universe is empty.
  3. Validate data-fetch and symbol resolution to report empty universes early.
  4. Caller guard: if (candlesSeries.Length == 0) return empty;

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)
    throw new ArgumentException("At least one candle series is required.", nameof(candlesSeries));

Type guard

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

Try / catch

try { result = calc.Calculate(candlesSeries, parameters); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "candlesSeries")
{ /* log empty universe; abort batch */ }

Prevention

When it happens

Trigger: Calling Calculate with candlesSeries = Array.Empty<GpuCandle[]>(). Triggered by empty symbol universes or data fetches returning no series.

Common situations: Symbol selection yields no instruments; market-data fetch empty for the range; holiday/weekend no-data; empty backtest universe; test missing candle data.

Related errors


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