Close By in MT5: match two opposite positions

Close By in MT5: match two opposite positions

On a hedging account, a buy and a sell can coexist on the same symbol. Close By is a specific way to close opposite positions against each other. Opening an opposite trade and leaving both positions active is a different operation.

Identify both tickets

The CTrade PositionCloseBy interface takes two position tickets. Confirm that the account and symbol support this operation, that directions are opposite and that both positions belong to the intended strategy. Never select a pair only because the symbol names match.

Consider unequal sizes

In a hypothetical pair of 0.05 lots and 0.03 lots, matching the smaller amount leaves exposure of 0.02 lots. Plan how the remaining position is managed. Inspect the resulting deals rather than assuming two original tickets imply two equal-sized closures.

Compare the complete cost

A useful demo comparison records the same starting positions, closure method, execution prices and all fees. Avoid judging from one deal row alone: paired closure accounting can distribute the reported result differently from two separate market closures.

Make the intent visible

A custom button or EA rule can name the two tickets and show the expected remainder before execution. For an AI-assisted change, ask for account-mode validation and result logging first. The goal is predictable position handling, not a claim that every broker or trade benefits from the same closure method.

CTrade Close By 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