Skip to content
All library documents

Closing Same-Direction Positions with a Hedge and Close-By Operation

Article MQL5 code base

Summary

This short note describes a method for closing a group of open positions when they all share the same instrument and direction, such as multiple long positions in one currency pair. The script first opens one larger trade in the opposite direction to hedge the combined exposure, then repeatedly uses a close-by operation to offset that hedge against the existing trades until the positions are closed.

The method depends on the positions being homogeneous in symbol and direction, and the note states a maximum of 500 open trades. It provides no code, platform-specific details, execution analysis, or evidence that the approach is reliable under different account or broker settings. Its subject is trade management mechanics rather than a signal for deciding when to enter or exit a market.

Key ideas

  • The procedure assumes all open positions use the same symbol and direction.
  • It opens one opposing trade to hedge the aggregate position before closing trades by offsetting them.
  • The note states that the method supports up to 500 open trades.
  • No platform details or execution results are provided.

Tags

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