Skip to content
All library documents

Closing Open Positions with Manual-Trade Filters and Error Handling

Article MQL5 code base

Summary

This document describes a chart-based utility for closing open positions in one action. A setting determines whether the operation targets only manually opened trades or also includes trades opened by an expert advisor. This filtering choice is important when several sources of exposure share an account, since an unrestricted close can affect automated positions as well as manual ones.

The note also explains a change to the close loop: instead of continuing indefinitely when an order close fails, the newer version checks the reported error and stops for a specified set of conditions, while retrying other failures. This is operational guidance for managing execution and failure behavior, not a tested trading strategy. It provides no evidence about fill quality, slippage, broker-specific error handling, or whether repeated attempts are appropriate in every market condition.

Key ideas

  • The utility closes open positions associated with the currently attached chart.
  • A setting can restrict closing to manual trades or include expert-advisor trades.
  • The revised failure handling stops on selected errors and retries other close failures.
  • The document gives no testing evidence about fills, slippage, or broker-specific behavior.

Tags

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