StockSharp/StockSharp · error · ArgumentOutOfRangeException

parameters

Error message

parameters

What it means

GpuMovingAverageCrossoverCalculator.Calculate throws ArgumentOutOfRangeException when the parameters array (GpuMovingAverageCrossoverParams[]) is empty. The method iterates over parameters to compute fast/slow MA crossover signals for each set; an empty array means nothing to compute and would produce a misleading empty result.

Source

Thrown at Algo.Gpu/Indicators/GpuMovingAverageCrossoverCalculator.cs:72

	/// <param name="accelerator">ILGPU accelerator.</param>
	public GpuMovingAverageCrossoverCalculator(Context context, Accelerator accelerator)
		: base(context, accelerator)
	{
		_paramsSeriesKernel = Accelerator.LoadAutoGroupedStreamKernel
			<Index3D, ArrayView<GpuCandle>, ArrayView<GpuIndicatorResult>, ArrayView<int>, ArrayView<int>, ArrayView<GpuMovingAverageCrossoverParams>>(MovingAverageCrossoverParamsSeriesKernel);
	}

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

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

View on GitHub (pinned to 601a191de6)

Solutions

  1. Check parameters.Length > 0 before calling Calculate
  2. Inspect the parameter sweep/generation logic upstream for empty-result bugs
  3. Log a warning and skip the indicator run when no parameter sets are configured

Example fix

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

// after
if (parameters is null || parameters.Length == 0)
    throw new InvalidOperationException("No MA crossover parameter sets configured.");
var results = calculator.Calculate(candlesSeries, parameters);
Defensive patterns

Strategy: validation

Validate before calling

// Validate before calling GpuMovingAverageCrossoverCalculator.Calculate
if (parameters is null || parameters.Length == 0)
{
    throw new InvalidOperationException("At least one MA crossover parameter set is required.");
}

Type guard

static bool IsValidParameters(GpuMovingAverageCrossoverParams[] parameters) =>
    parameters is { Length: > 0 };

Try / catch

try
{
    var results = calculator.Calculate(candlesSeries, parameters);
}
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == nameof(parameters))
{
    logger.LogWarning("Empty parameters passed to MA crossover calculator");
    return Array.Empty<GpuIndicatorResult[][]>();
}

Prevention

When it happens

Trigger: Calling Calculate with Array.Empty<GpuMovingAverageCrossoverParams>() or a zero-length parameters array as the second argument.

Common situations: Parameter optimization grid filtered out all fast/slow period combinations; config deserialization yielded an empty list; dynamic parameter builder has a bug producing zero entries.

Related errors


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