Designing a Lot-Step-Safe Partial Close Engine with R-Multiple Targets
Summary
This article explains a reusable MQL5 engine for scaling out of positions at configurable profit targets. Each ladder rung specifies an R-multiple trigger, a percentage of the original entry volume to close, and an optional instruction to move the stop to breakeven. R is defined as the entry-to-stop distance, allowing target levels to scale with the risk of each position. The engine stores the original entry price, stop, risk distance, and volume so later calculations are not distorted by earlier partial closes or stop changes.
The design separates volume normalization, trade execution, breakeven management, chart drawing, and coordination. It aims to round close sizes to the broker's lot step and avoid leaving a remainder below the minimum tradable size; the article also describes selecting a supported filling mode. A verification script is included for core formulas, but the text does not provide trading-performance evidence. It notes limits including broker-specific rejections, unusual spread behavior, and chart state not persisting after a terminal restart.
Key ideas
- Ladder triggers use multiples of the original entry-to-stop distance so targets scale with trade risk.
- Each close percentage applies to original entry volume, not the volume remaining after earlier scale-outs.
- The engine freezes the position's starting state for consistent target and close-volume calculations.
- Close sizes are normalized to broker lot constraints, including the minimum tradable remainder.
- A ladder rung can request a stop move to breakeven, but the design does not establish strategy profitability.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.