StockSharp/StockSharp · error · ArgumentOutOfRangeException
LocalizedStrings.InvalidValue
Error message
LocalizedStrings.InvalidValue
What it means
MassIndex.EmaLength sets the period on both the inner single and double EMAs that the Mass Index accumulates. Each EMA needs at least 2 points, so the setter throws ArgumentOutOfRangeException with LocalizedStrings.InvalidValue for value < 2 before resetting both inner EMAs and the sum.
Source
Thrown at Algo.Indicators/MassIndex.cs:46
_sum = new();
Length = 25;
}
/// <summary>
/// <see cref="ExponentialMovingAverage"/>
/// </summary>
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.EMAKey,
Description = LocalizedStrings.ExponentialMovingAverageKey,
GroupName = LocalizedStrings.GeneralKey)]
public int EmaLength
{
get => _singleEma.Length;
set
{
if (value < 2)
throw new ArgumentOutOfRangeException(nameof(value), value, LocalizedStrings.InvalidValue);
_singleEma.Length = _doubleEma.Length = value;
Reset();
}
}
/// <inheritdoc />
public override int NumValuesToInitialize
=> _singleEma.NumValuesToInitialize + _sum.NumValuesToInitialize - 1;
/// <inheritdoc />
public override IndicatorMeasures Measure => IndicatorMeasures.MinusOnePlusOne;
/// <inheritdoc />
protected override bool CalcIsFormed() => _sum.IsFormed;
/// <inheritdoc />
protected override decimal? OnProcessDecimal(IIndicatorValue input)View on GitHub (pinned to 601a191de6)
Solutions
- Set EmaLength to at least 2 (standard Mass Index uses 9).
- Clamp: `mi.EmaLength = Math.Max(2, raw)` before assigning.
- Validate the bound at the input/config boundary.
Example fix
// before mi.EmaLength = 1; // after mi.EmaLength = 9;
Defensive patterns
Strategy: validation
Validate before calling
static int SanitizeEmaLength(int v) => Math.Max(2, v); // usage: mi.EmaLength = SanitizeEmaLength(raw);
Type guard
static bool IsValidEmaLength(int v) => v >= 2;
Try / catch
try { mi.EmaLength = raw; }
catch (ArgumentOutOfRangeException) { mi.EmaLength = 9; } Prevention
- Clamp to >= 2 since both inner EMAs share the period.
- Reject 0/1 in the UI/config layer.
- Default to the standard Mass Index EMA period of 9.
When it happens
Trigger: Setting MassIndex.EmaLength to 0 or 1, e.g. `mi.EmaLength = 1`. The conventional Mass Index EMAs use 9.
Common situations: UI period field below 2, deserialized config with a 1, or copying a period from a non-EMA indicator that allowed 1.
Related errors
- LocalizedStrings.InvalidValue
- LocalizedStrings.InvalidValue
- LocalizedStrings.InvalidValue
- LocalizedStrings.InvalidValue
- LocalizedStrings.InvalidValue
AI-assisted analysis of StockSharp/StockSharp@601a191de6 (2026-08-13).
Data as JSON: /api/errors/d07fc89c930a2b9d.
Report an issue: GitHub.