Fill triggered stop limit orders as limit orders on later bars - #9787
Merged
Martin-Molinero merged 3 commits intoSep 10, 2026
Merged
Conversation
Track the time a stop limit order's stop was triggered, the end time of the data that triggered it, and fill the limit leg like a resting limit order on data that is entirely after it. The trigger bar keeps the close based test since its range may predate the trigger. The time is serialized, cloned and propagated through the order update event. Closes QuantConnect#9773 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Zic3mz9ZogfCvhzoTXvDG
Brokerages that only flip the stop triggered flag get the algorithm time as the trigger time, so the fill models can still tell later data apart. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Zic3mz9ZogfCvhzoTXvDG
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Zic3mz9ZogfCvhzoTXvDG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #9773
Once a stop limit order's stop has triggered on an earlier bar, every later bar is entirely post trigger, but the fill models kept applying the trigger bar's close based test, so a triggered stop limit never filled on an intra bar limit touch.
StopLimitOrdergets a nullableStopTriggeredTimein UTC, the end time of the data that triggered the stop. It is cloned, serialized asstopTriggeredTime(omitted when null) and deserialized, along withstopTriggeredwhich was previously dropped. Missing fields deserialize to their defaults so existing payloads still load.FillModelandEquityFillModelset the time when the stop triggers. On data that starts at or after the trigger time and ends after it, the limit leg fills under the resting limit rule, reusing the existing limit fill implementations (the equity one keeps the favorable gap open fill). The trigger bar keeps the close based test since its range may predate the trigger. Zero duration data at the exact trigger time, like a tick batch sharing the trigger tick time stamp or a live re-scan, stays on the close based rule.OrderUpdateEventcarries the time, the backtesting brokerage emits it and the transaction handler applies it. Brokerages that only flip the flag get the current algorithm time, and the time is never cleared.Related Issue
#9773
Motivation and Context
A live paper deployment had a buy stop limit triggered on the first bar, six later bars traded through the limit and none closed below it, so the order stayed submitted for hours. A plain limit order placed at the trigger would have filled.
Requires Documentation Change
StopLimitOrder.StopTriggeredTimeis a new public property.How Has This Been Tested?
EquityFillModelTestscovering fills at the limit and at the open on a favorable gap on the bar after the trigger, for buys and sells, and no fill from the trigger bar range even when re-scanned.ImmediateFillModelTestscovering the base model for both directions, including the re-scan case.OrderJsonConverterTestsround trip the flag and time and cover payloads without them.BrokerageTransactionHandlerTestscover applying the update with and without the time, and ignoring it when the algorithm is stopped.StopLimitOrderRegressionAlgorithm(C# and Python) asserts the trigger time is set before the fill.UpdateOrderRegressionAlgorithmstatistics changed because its stop limit orders now fill on the first later bar that trades through the limit.OrderTicketDemoAlgorithm,SplitEquityRegressionAlgorithmandStopLimitOrderRegressionAlgorithmonly changed their order list hash from the new serialized field.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>🤖 Generated with Claude Code
https://claude.ai/code/session_013Zic3mz9ZogfCvhzoTXvDG