QuantConnect/Lean · error · RegressionTestException
Unexpected open order for emitted insight: {order}
Error message
Unexpected open order for emitted insight: {order} What it means
After asserting an order exists, this checks the order's Direction is Sell and its Symbol equals _symbol. The Down insight must produce a Sell order on the correct symbol. A mismatch means the PCM/Execution produced an order of the wrong direction (e.g. Buy for a Down insight) or for the wrong symbol.
Source
Thrown at Algorithm.CSharp/EmitInsightNoAlphaModelAlgorithm.cs:87
if (order != null)
{
throw new RegressionTestException($"Unexpected open order {order}");
}
EmitInsights(Insight.Price(_symbol, Resolution.Daily, 10, InsightDirection.Down));
// emitted insight should have triggered a new order
order = Transactions.GetOpenOrders(_symbol).FirstOrDefault();
if (order == null)
{
throw new RegressionTestException("Expected open order for emitted insight");
}
if (order.Direction != OrderDirection.Sell
|| order.Symbol != _symbol)
{
throw new RegressionTestException($"Unexpected open order for emitted insight: {order}");
}
SetHoldings(_symbol, 1);
}
}
public override void OnEndOfAlgorithm()
{
var holdings = Securities[_symbol].Holdings;
if (Math.Sign(holdings.Quantity) != -1)
{
throw new RegressionTestException("Unexpected holdings");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>View on GitHub (pinned to d2c3659f87)
Solutions
- Inspect the insight Direction and the resulting PCM target sign for consistency.
- Compare the order.Symbol SID against _symbol to rule out canonical-symbol remapping.
- Fix the PCM target calculation so a Down insight yields a Sell (negative target).
Defensive patterns
Strategy: validation
Validate before calling
if (order.Direction != OrderDirection.Sell || order.Symbol != _symbol)
{
Log($"Insight->order mismatch: insight=Down, order={order.Direction} sym={order.Symbol}");
} Prevention
- Verify PCM target-sign logic maps Down insights to negative targets (Sell).
- Compare order.Symbol SID against the insight symbol to catch canonical remapping.
- Add a unit test on the PCM for each InsightDirection.
When it happens
Trigger: The PCM inverted the direction (Down insight -> Buy), or the order's symbol does not match _symbol due to canonical symbol mapping.
Common situations: PCM target-sign logic bug (negative insight -> positive target -> Buy); symbol canonicalization (e.g. mapped/equity mapping) changing the order symbol; insight direction enum handling change.
Related errors
- Expected open order for emitted insight
- Unexpected holdings
- Option was not sold
- Option was not assigned
- Stock was not assigned
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/a9222f17754c2ad3.
Report an issue: GitHub.