{"record":{"id":"0d6b3a007e69e0bc","repo":"QuantConnect/Lean","slug":"security-price-error-price-should-change-every-ne","errorCode":null,"errorMessage":"Security Price error. Price should change every new hour","messagePattern":"Security Price error\\. Price should change every new hour","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/CustomUniverseWithBenchmarkRegressionAlgorithm.cs","lineNumber":103,"sourceCode":"            {\n                if (bar.IsFillForward\n                    || bar.Period != TimeSpan.FromMinutes(1))\n                {\n                    // bar should always be the Minute resolution one here\n                    throw new RegressionTestException(\"Unexpected Bar error\");\n                }\n                if (_previousTime.Date == slice.Time.Date\n                    && (slice.Time - _previousTime) != TimeSpan.FromMinutes(1))\n                {\n                    throw new RegressionTestException(\"For the same date expected data updates every 1 minute\");\n                }\n            }\n            else\n            {\n                if (slice.Time.Minute == 0\n                    && _previousSecurityValue == security.Price)\n                {\n                    throw new RegressionTestException($\"Security Price error. Price should change every new hour\");\n                }\n                if (slice.Time.Minute != 0\n                    && _previousSecurityValue != security.Price\n                    && security.IsTradable)\n                {\n                    throw new RegressionTestException($\"Security Price error. Price should not change every minute\");\n                }\n            }\n            _previousSecurityValue = security.Price;\n\n            // assert benchmark updates only on date change\n            var currentValue = Benchmark.Evaluate(slice.Time);\n            if (_previousTime.Hour == slice.Time.Hour)\n            {\n                if (currentValue != _previousBenchmarkValue)\n                {\n                    throw new RegressionTestException($\"Benchmark value error - expected: {_previousBenchmarkValue} {_previousTime}, actual: {currentValue} {slice.Time}. \" +\n                                        \"Benchmark value should only change when there is a change in hours\");","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/CustomUniverseWithBenchmarkRegressionAlgorithm.cs#L85-L121","documentation":"This RegressionTestException is thrown in OnData when the universe is NOT selected (_universeSelected == false) and slice.Time.Minute == 0 (an hour boundary). It asserts that the security price changed from the previous slice, verifying that Hour-resolution data delivers a new price at each new hour. LEAN throws it because at hour boundaries the SPY subscription (Hour resolution) must reflect a genuinely new data point.","triggerScenarios":"At Minute == 0 (top of the hour), security.Price equals _previousSecurityValue — the price did not update when a new hour bar arrived. This means the hour-resolution data feed delivered a bar with the same price as the previous one, which should only happen for non-tradable or fill-forward data.","commonSituations":"Hour data files contain duplicate prices across consecutive hours, fill-forward logic generates bars with stale prices at hour boundaries, or the security's Price property is not being updated from the latest bar due to a data-feed or price-calculation regression.","solutions":["Log security.Price and _previousSecurityValue at the throw to confirm the stale price.","Inspect the hour-resolution data file to verify prices differ across consecutive hours.","Check that the security's Price is derived from the latest bar's close, not a cached or fill-forward value.","If testing engine changes, trace how hour-resolution bars update Security.Price to ensure it reflects the new bar."],"exampleFix":"// before\nif (slice.Time.Minute == 0 && _previousSecurityValue == security.Price)\n{\n    throw new RegressionTestException($\"Security Price error. Price should change every new hour\");\n}\n\n// after — diagnostic\nif (slice.Time.Minute == 0 && _previousSecurityValue == security.Price)\n{\n    throw new RegressionTestException($\"Price unchanged at hour boundary {slice.Time}: prev={_previousSecurityValue}, current={security.Price}\");\n}","handlingStrategy":"validation","validationCode":"// Validate price change at hour boundary\nif (slice.Time.Minute == 0)\n{\n    if (_previousSecurityValue == security.Price)\n        Log($\"Price unchanged at hour boundary {slice.Time}: {security.Price}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify hour-resolution data files have distinct prices across consecutive hours.","Confirm Security.Price is derived from the latest bar's close.","Check that the security updates its price from each new bar, not a cached value."],"tags":["quantconnect","lean","hour-data","price","resolution","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}