Partial close in MQL5: reduce a position exactly once

Partial close in MQL5: reduce a position exactly once

Closing part of a position can leave a smaller remainder to follow another exit rule. The interesting implementation challenge is remembering that the reduction already happened, especially when the EA receives another tick or restarts.

Check the account model

The CTrade PositionClosePartial method is documented for hedging accounts. Prefer the intended position ticket when several positions share a symbol. A successful method return is not the final server execution result; inspect the trade return code and resulting position.

Work through the remainder

For an illustrative 0.05-lot position, closing 0.02 leaves 0.03. Both quantities must respect the symbol volume rules. A percentage calculation can produce a quantity below the minimum or an invalid remainder, so define the rounding and skip behaviour in advance.

Test the once-only rule

Create a demo position, trigger the scale-out condition, and let several more ticks arrive. The remainder should not be repeatedly halved. Restart the EA and repeat the observation. Reconstruct completion from recorded trades or durable state instead of relying only on a temporary boolean.

Ask AI for a narrow change

Specify the account mode, ticket ownership, trigger, fraction and residual-volume policy. Request a before-and-after log showing requested volume, executed reduction and remaining volume. This turns a vague instruction such as take some profit into a reviewable behaviour.

CTrade partial close reference

Back to top

MQLume Bespoke

Built around your ambition.

Explore bespoke services →

Have something more specific in mind?

Ask us about advanced custom development. Share your requirements through private support or email; we will discuss the scope and quote separately.

100% committed to following up on your delivery and support requests.

Free downloads. Real source files.

FREE

Lizard [MQLume]

MQL5 / MT5Version v2.1

Free editable gold breakout project with six independently selectable cores, session filters and flexible position sizing.

US$99.00FREE
FREE

Scraper Gold [MQLume]

MQL5 / MT5Version v3.7

Free editable source with compiled EX5: four gold breakout engines with independent profiles, sizing, direction and exits.

US$95.00FREE
MQLume

More to explore. A community to share it with.

Stay close to MQLume, wherever you like to learn.

YouTube

See our EAs in action. Explore backtests, walkthroughs and practical guides.

Watch on YouTube

Telegram

Meet other EA users, share ideas and keep up with what’s new.

Join the community Follow official updates

Cart

One personal-use licence per project. Each project can be added once.

Your cart is waiting for its first passenger.

Choose an EA or source edition to get started.

Continue shopping