{"record":{"id":"d07fc89c930a2b9d","repo":"StockSharp/StockSharp","slug":"localizedstrings-invalidvalue-d07fc8","errorCode":null,"errorMessage":"LocalizedStrings.InvalidValue","messagePattern":"LocalizedStrings\\.InvalidValue","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Algo.Indicators/MassIndex.cs","lineNumber":46,"sourceCode":"\t\t_sum = new();\n\t\tLength = 25;\n\t}\n\n\t/// <summary>\n\t/// <see cref=\"ExponentialMovingAverage\"/>\n\t/// </summary>\n\t[Display(\n\t\tResourceType = typeof(LocalizedStrings),\n\t\tName = LocalizedStrings.EMAKey,\n\t\tDescription = LocalizedStrings.ExponentialMovingAverageKey,\n\t\tGroupName = LocalizedStrings.GeneralKey)]\n\tpublic int EmaLength\n\t{\n\t\tget => _singleEma.Length;\n\t\tset\n\t\t{\n\t\t\tif (value < 2)\n\t\t\t\tthrow new ArgumentOutOfRangeException(nameof(value), value, LocalizedStrings.InvalidValue);\n\n\t\t\t_singleEma.Length = _doubleEma.Length = value;\n\t\t\tReset();\n\t\t}\n\t}\n\n\t/// <inheritdoc />\n\tpublic override int NumValuesToInitialize\n\t\t=> _singleEma.NumValuesToInitialize + _sum.NumValuesToInitialize - 1;\n\n\t/// <inheritdoc />\n\tpublic override IndicatorMeasures Measure => IndicatorMeasures.MinusOnePlusOne;\n\n\t/// <inheritdoc />\n\tprotected override bool CalcIsFormed() => _sum.IsFormed;\n\n\t/// <inheritdoc />\n\tprotected override decimal? OnProcessDecimal(IIndicatorValue input)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/StockSharp/StockSharp/blob/601a191de678bff83da28b14828f8885214ca71c/Algo.Indicators/MassIndex.cs#L28-L64","documentation":"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.","triggerScenarios":"Setting MassIndex.EmaLength to 0 or 1, e.g. `mi.EmaLength = 1`. The conventional Mass Index EMAs use 9.","commonSituations":"UI period field below 2, deserialized config with a 1, or copying a period from a non-EMA indicator that allowed 1.","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."],"exampleFix":"// before\nmi.EmaLength = 1;\n// after\nmi.EmaLength = 9;","handlingStrategy":"validation","validationCode":"static int SanitizeEmaLength(int v) => Math.Max(2, v);\n// usage: mi.EmaLength = SanitizeEmaLength(raw);","typeGuard":"static bool IsValidEmaLength(int v) => v >= 2;","tryCatchPattern":"try { mi.EmaLength = raw; }\ncatch (ArgumentOutOfRangeException) { mi.EmaLength = 9; }","preventionTips":["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."],"tags":["stocksharp","indicator","argument-validation","mass-index","ema"],"backgroundTag":null,"analyzedSha":"601a191de678bff83da28b14828f8885214ca71c","analyzedAt":"2026-08-13T20:43:24.460Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}