TakeProfitAndStopLossOrdersAnalysis
QuantConnect.Lean.Engine.Results.Analysis.Analyses.TakeProfitAndStopLossOrdersAnalysis
Bases: BaseResultsAnalysis
Detects TP/SL order pairs where both filled, or where the surviving leg was not cancelled when the other filled.
is_state_based
is_state_based: bool
This analysis reads the current orders collection instead of scanning the order event and log streams, so its in-run findings are replaced on every run.
issue
issue: str
Gets the description of the TP/SL order handling issue.
weight
weight: int
Gets the severity weight for this TP/SL orders analysis.
runs_in_run
runs_in_run: bool
Whether this analysis can also run while the backtest is still in progress, against a snapshot of the intermediate results. Most analyses read only the result snapshot, so this defaults to true. Analyses that need the completed run (runtime errors, equity curves, final statistics, completion logs) or that read algorithm state that is not safe to access while it runs override this to leave them to the final analysis only.
run
run(
parameters: ResultsAnalysisRunParameters,
) -> Sequence[Analysis]
Signature descriptions:
-
Runs the take-profit and stop-loss orders analysis against the provided backtest parameters.
-
Groups orders into TP/SL pairs by symbol, quantity, and creation time, then delegates to sub-analyses that check for both-filled and dangling-order scenarios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orders
|
Optional[ICollection[Order]]
|
All orders from the backtest result. |
None
|
language
|
Optional[Language]
|
The programming language the algorithm is written in. |
None
|
Returns:
| Type | Description |
|---|---|
Sequence[Analysis]
|
Aggregated analysis results from all sub-analyses that detected issues. |
single_response
single_response(
sample: Any, solutions: Sequence[str] = None
) -> Sequence[Analysis]
single_response(
sample: Any,
count: Optional[int],
solutions: Sequence[str] = None,
) -> Sequence[Analysis]
Wraps a single QuantConnect.Analysis in a one-element read-only list.
create_aggregated_response
Filters responses to those with solutions, prefixes the class name, and returns a flat list.
This Class is protected.
format_code
format_code(code: str, language: Language) -> str
Formats the specified code string according to the conventions of the given programming language.
This Class is protected.