Skip to content
All library documents

Implementing a Trailing Stop and Profit Exit in a Trading Strategy

Article BigQuant

Summary

This forum post responds to a question about selling after a 10% gain or cutting a position after a 10% loss. The included example checks open equity positions against current prices, retrieves the highest price since purchase, and exits when price falls 7% below that high. It also closes a position when its price rises more than 7% above cost. The example illustrates how strategy code can inspect position data and submit orders to close holdings when exit conditions are met.

The implementation does not match the question’s proposed thresholds: it uses a trailing drawdown from the post-purchase high for its loss exit, rather than a fixed 10% loss from cost, and uses a 7% gain rather than 10%. A trailing stop can allow a position to remain open after an initial rise while protecting some accumulated gains, but the example does not explain order execution, price gaps, or whether the platform’s historical data and order handling support the intended behavior. It provides code rather than results, so no evidence of strategy performance is offered.

Key ideas

  • The example closes positions based on price relative to cost and the post-entry high.
  • Its loss exit is a 7% trailing decline from the highest price since purchase.
  • Its profit exit triggers above a 7% gain from cost.
  • These thresholds differ from the question’s proposed 10% gain and loss rules.
  • The post does not report testing or execution outcomes.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.