Skip to content

[RiskEngine] Cannot check TRAILING_STOP_MARKET order risk when trigger_price is None #3160

@GianC0

Description

@GianC0

Bug Report

Confirmation

Before opening a bug report, please confirm:

  • I've re-read the relevant sections of the documentation.
  • I've searched existing issues and discussions to avoid duplicates.
  • I've reviewed or skimmed the source code (or examples) to confirm the behavior is not by design.
  • I've tested this issue using a recent development wheel (dev develop or a nightly) and can still reproduce it.

Checking a recent development wheel can save time because the issue may already have been fixed.
You can install a development wheel by running:

pip install -U nautilus_trader --pre --index-url https://packages.nautechsystems.io/simple

See the [development-wheels](https://github.com/nautechsystems/nautilus_trader#development-wheels) section for more details.

Expected Behavior

The risk engine should be able to check order risk for TRAILING_STOP_MARKET orders when trigger_price is None but trailing_offset and trailing_offset_type are properly configured.

Since trailing stop orders dynamically calculate the trigger price based on the market price and trailing offset, the risk engine should:

  1. Recognize that trailing_offset and trailing_offset_type are set
  2. Calculate an estimated trigger price based on the current market price and trailing offset
  3. Use this calculated price to perform standard risk checks

This would allow proper risk validation for trailing stop orders without requiring an explicit trigger price at order creation time.

Actual Behavior

The risk engine cannot perform risk checks on TRAILING_STOP_MARKET orders when trigger_price is None, even when both trailing_offset and trailing_offset_type are properly set. The risk engine logs the following warning:

WARNING: Backtest-MyBacktest.RiskEngine: Cannot check TRAILING_STOP_MARKET order risk: no trigger price was set

This prevents the risk engine from validating the order, even though the trailing offset parameters provide sufficient information to estimate risk bounds.

Steps to Reproduce the Problem

  1. Create a trailing stop market order with trigger_price=None but with valid trailing_offset and trailing_offset_type parameters
  2. Submit the order through the order factory
  3. Observe the warning message from the risk engine indicating it cannot check order risk

Code Snippets or Logs

trailing_order = self.order_factory.trailing_stop_market(
    instrument_id=instrument_id,
    order_side=order_side,
    quantity=Quantity.from_int(abs(int(quantity))),
    trigger_type=TriggerType.LAST_PRICE,
    trigger_price=None,
    trailing_offset=Decimal(trailing_stop_max_bps * 10000),
    trailing_offset_type=TrailingOffsetType.BASIS_POINTS,
)
self.submit_order(trailing_order)

Log output:

WARNING: Backtest-MyBacktest.RiskEngine: Cannot check TRAILING_STOP_MARKET order risk: no trigger price was set

Specifications

  • OS platform: Windows 11 Home Version 10.0.26200 Build 26200
  • Python version: 3.12.1
  • nautilus_trader version: 1.222.0a20251104

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions