Closing Orders at an Account Drawdown Threshold
Summary
The document describes a MetaTrader-style utility that closes matching open orders when calculated losses reach a user-set percentage of account balance. A caller supplies a drawdown threshold and a magic number to select orders; using zero is described as selecting all orders. The close routine filters by the current symbol and includes orders with the specified magic number or magic number zero.
The implementation sums open-order profit, converts a negative total to a loss, and compares that loss with the threshold. A persistent flag keeps attempting closure until a successful close resets it. This is presented as a code utility, not a tested risk-control strategy: there are no performance results or validation details. The calculation uses balance rather than equity and, as shown, its order-selection behavior and loss aggregation may not match the stated intent for every account or strategy. Execution failures are reported, but the document does not discuss slippage, partial fills, or broader account-level safeguards.
Key ideas
- The routine compares aggregated open-order losses with a percentage of account balance.
- A magic number filters orders, while zero is described as selecting all orders.
- The close loop also restricts orders to the current chart symbol.
- A flag keeps closure attempts active until an order close succeeds.
- The document supplies implementation details but no testing or performance evidence.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.