Skip to content

TrailingStopOrder

QuantConnect.Orders.TrailingStopOrder

TrailingStopOrder()
TrailingStopOrder(
    symbol: Union[Symbol, str, BaseContract],
    quantity: float,
    stop_price: float,
    trailing_amount: float,
    trailing_as_percentage: bool,
    time: Union[datetime, date],
    tag: str = ...,
    properties: IOrderProperties = None,
)
TrailingStopOrder(
    symbol: Union[Symbol, str, BaseContract],
    quantity: float,
    trailing_amount: float,
    trailing_as_percentage: bool,
    time: Union[datetime, date],
    tag: str = ...,
    properties: IOrderProperties = None,
)

Bases: StopMarketOrder

Trailing Stop Order Type Definition

Signature descriptions:

  • Default constructor for JSON Deserialization:

  • New Trailing Stop Market Order constructor

  • New Trailing Stop Market Order constructor. It creates a new Trailing Stop Market Order with an initial stop price calculated by subtracting (for a sell) or adding (for a buy) the trailing amount to the current market price.

Parameters:

Name Type Description Default
symbol Optional[Union[Symbol, str, BaseContract]]

Symbol asset being traded

None
quantity Optional[float]

Quantity of the asset to be traded

None
stop_price Optional[float]

Initial stop price at which the order should be triggered

None
trailing_amount Optional[float]

The trailing amount to be used to update the stop price

None
trailing_as_percentage Optional[bool]

Whether the trailing_amount is a percentage or an absolute currency value

None
time Optional[Union[datetime, date]]

Time the order was placed

None
tag Optional[str]

User defined data tag for this order

...
properties Optional[IOrderProperties]

The properties for this order

None

trailing_amount

trailing_amount: float

Trailing amount for this trailing stop order

trailing_as_percentage

trailing_as_percentage: bool

Determines whether the trailing_amount is a percentage or an absolute currency value

type

type: OrderType

StopLimit Order Type

id

id: int

Order ID.

contingent_id

contingent_id: int

Order id to process before processing this order.

broker_id

broker_id: List[str]

Brokerage Id for this order for when the brokerage splits orders into multiple pieces

symbol

symbol: Symbol

Symbol of the Asset

price

price: float

Price of the Order.

price_currency

price_currency: str

Currency for the order price

time

time: datetime

Gets the utc time the order was created.

created_time

created_time: datetime

Gets the utc time this order was created. Alias for time

last_fill_time

last_fill_time: Optional[datetime]

Gets the utc time the last fill was received, or null if no fills have been received

last_update_time

last_update_time: Optional[datetime]

Gets the utc time this order was last updated, or null if the order has not been updated.

canceled_time

canceled_time: Optional[datetime]

Gets the utc time this order was canceled, or null if the order was not canceled.

quantity

quantity: float

Number of shares to execute.

status

status: OrderStatus

Status of the Order

time_in_force

time_in_force: TimeInForce

Order Time In Force

tag

tag: str

Tag the order with some custom data

properties

properties: IOrderProperties

Additional properties of the order

security_type

security_type: SecurityType

The symbol's security type

direction

direction: OrderDirection

Order Direction Property based off Quantity.

absolute_quantity

absolute_quantity: float

Get the absolute quantity for this order

value

value: float

Deprecated

Please use Order.GetValue(security) or security.Holdings.HoldingsValue

order_submission_data

order_submission_data: OrderSubmissionData

Gets the price data at the time the order was submitted

is_marketable

is_marketable: bool

Returns true if the order is a marketable order.

group_order_manager

group_order_manager: GroupOrderManager

Manager for the orders in the group if this is a combo order

price_adjustment_mode

price_adjustment_mode: DataNormalizationMode

The adjustment mode used on the order fill price

stop_price

stop_price: float

Stop price for this stop market order.

apply_update_order_request

apply_update_order_request(
    request: UpdateOrderRequest,
) -> None

Modifies the state of this order to match the update request

Parameters:

Name Type Description Default
request UpdateOrderRequest

The request to update this order object

required

calculate_stop_price

calculate_stop_price(
    current_market_price: float,
    trailing_amount: float,
    trailing_as_percentage: bool,
    direction: OrderDirection,
) -> float

Calculates the stop price for a trailing stop order given the current market price

Parameters:

Name Type Description Default
current_market_price float

The current market price

required
trailing_amount float

The trailing amount to be used to update the stop price

required
trailing_as_percentage bool

Whether the trailing_amount is a percentage or an absolute currency value

required
direction OrderDirection

The order direction

required

Returns:

Type Description
float

The stop price for the order given the current market price.

clone

clone() -> Order

Creates a deep-copy clone of this order

Returns:

Type Description
Order

A copy of this order.

get_default_tag

get_default_tag() -> str

Gets the default tag for this order

Returns:

Type Description
str

The default tag.

to_string

to_string() -> str

Returns a string that represents the current object.

Returns:

Type Description
str

A string that represents the current object.

try_update_stop_price

try_update_stop_price(
    current_market_price: float,
    current_stop_price: float,
    trailing_amount: float,
    trailing_as_percentage: bool,
    direction: OrderDirection,
    updated_stop_price: Optional[float],
) -> Tuple[bool, float]

Tries to update the stop price for a trailing stop order given the current market price

Parameters:

Name Type Description Default
current_market_price float

The current market price

required
current_stop_price float

The current trailing stop order stop price

required
trailing_amount float

The trailing amount to be used to update the stop price

required
trailing_as_percentage bool

Whether the trailing_amount is a percentage or an absolute currency value

required
direction OrderDirection

The order direction

required
updated_stop_price Optional[float]

The updated stop price

required

Returns:

Type Description
Tuple[bool, float]

Whether the stop price was updated. This only happens when the distance between the current stop price and the current market price is greater than the trailing amount, which will happen when the market price raises/falls for sell/buy orders respectively.

copy_to

copy_to(order: Order) -> None

Copies base Order properties to the specified order

This codeEntityType is protected.

Parameters:

Name Type Description Default
order Order

The target of the copy

required

create_order

create_order(request: SubmitOrderRequest) -> Order

Creates an Order to match the specified request

Parameters:

Name Type Description Default
request SubmitOrderRequest

The SubmitOrderRequest to create an order for

required

Returns:

Type Description
Order

The Order that matches the request.

create_positions

create_positions(
    securities: SecurityManager,
) -> Iterable[IPosition]

Creates an enumerable containing each position resulting from executing this order.

Returns:

Type Description
Iterable[IPosition]

An enumerable of positions matching the results of executing this order.

get_value

get_value(security: Security) -> float

Gets the value of this order at the given market price in units of the account currency NOTE: Some order types derive value from other parameters, such as limit prices

Parameters:

Name Type Description Default
security Security

The security matching this order's symbol

required

Returns:

Type Description
float

The value of this order given the current market price.

get_value_impl

get_value_impl(security: Security) -> float

Gets the order value in units of the security's quote currency

This codeEntityType is protected.

Parameters:

Name Type Description Default
security Security

The security matching this order's symbol

required