{"record":{"id":"c639456a4d96fbb9","repo":"QuantConnect/Lean","slug":"there-should-not-be-more-than-5-data-points-but-t","errorCode":null,"errorMessage":"There should not be more than 5 data points, but there were {_dataPoints}","messagePattern":"There should not be more than 5 data points, but there were (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/CustomSecurityDataFilterRegressionAlgorithm.cs","lineNumber":50,"sourceCode":"\n        public override void Initialize()\n        {\n            SetCash(2500000);\n            SetStartDate(2013, 10, 7);\n            SetEndDate(2013, 10, 7);\n\n            var security = AddSecurity(SecurityType.Equity, \"SPY\");\n            security.SetDataFilter(new CustomDataFilter());\n            _dataPoints = 0;\n        }\n\n        public override void OnData(Slice slice)\n        {\n            _dataPoints++;\n            SetHoldings(\"SPY\", 0.2);\n            if (_dataPoints > 5)\n            {\n                throw new RegressionTestException($\"There should not be more than 5 data points, but there were {_dataPoints}\");\n            }\n        }\n\n        private class CustomDataFilter : ISecurityDataFilter\n        {\n            public bool Filter(Security vehicle, BaseData data)\n            {\n                // Skip data after 9:35am\n                if (data.Time >= new DateTime(2013, 10, 7, 9, 35, 0, 0))\n                {\n                    return false;\n                }\n                else\n                {\n                    return true;\n                }\n            }\n        }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/CustomSecurityDataFilterRegressionAlgorithm.cs#L32-L68","documentation":"Asserts the custom ISecurityDataFilter actually reduced the feed: with SPY minute data on 2013-10-07, the filter drops everything at/after 09:35, leaving 5 points (09:30-09:34). If OnData fires more than 5 times, the filter was not applied and unfiltered bars reached the algorithm.","triggerScenarios":"Calling security.SetDataFilter(new CustomDataFilter()) in Initialize but still receiving >5 OnData calls, indicating SetDataFilter did not register, or the filter's Filter returned true for post-09:35 bars.","commonSituations":"SetDataFilter called on a different Security instance than the one feeding OnData; filter time comparison uses the wrong time zone (UTC vs exchange) so data.Time never reaches the threshold; or a Lean version change altered when filters run in the pipeline.","solutions":["Call SetDataFilter on the exact Security returned by AddSecurity/AddEquity and store that reference.","Make the Filter comparison use exchange-local time (data.Time is already in the exchange zone for most feeds) consistent with the 09:35 threshold.","Verify the CustomDataFilter implements ISecurityDataFilter.Filter(Security, BaseData) and returns false for data.Time >= 2013-10-07 09:35.","Confirm data resolution is Minute (so the 09:30-09:34 five-bar expectation holds); a coarser resolution changes the count."],"exampleFix":"// before: filter set on a throwaway security reference\nAddEquity(\"SPY\").SetDataFilter(new CustomDataFilter());\n\n// after: keep and configure the same instance\nvar security = AddSecurity(SecurityType.Equity, \"SPY\");\nsecurity.SetDataFilter(new CustomDataFilter());","handlingStrategy":"validation","validationCode":"// Validate the filter is installed and reduces the feed\nvar security = AddEquity(\"SPY\", Resolution.Minute);\nsecurity.SetDataFilter(new CustomDataFilter());\nDebug.Assert(security.Subscriptions.First().Filter is CustomDataFilter);","typeGuard":"bool FilterInstalled(Security s) => s.Subscriptions.Any(x => x.Filter is CustomDataFilter);","tryCatchPattern":null,"preventionTips":["Call SetDataFilter on the exact Security returned by AddEquity.","Use exchange-local time consistently in Filter comparisons.","Confirm resolution is Minute when the expected count assumes minute bars."],"tags":["regression-test","data-filter","equities","minute-data"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}