Skip to content
All library documents

Using an Expert Advisor to Close Positions from a Chart Indicator

Article MQL5 articles

Summary

This installment in a MetaTrader replay and simulation series describes how a chart indicator can trigger a request to close a displayed position. The indicator cannot alter positions on the trading server directly; an Expert Advisor must receive its event and submit the trading request. The article proposes adding a dedicated event for this action and handling it in the Expert Advisor, which selects the position by ticket and sends an opposing market deal for its volume.

The separate event matters for hedging accounts: reusing a general close-all event could close multiple positions when the intent is to close one. The article also places this mechanism within a larger interaction design involving chart controls, indicators, and an Expert Advisor. It explains the Expert Advisor side of the change, while deferring the fuller position-indicator implementation to a later installment. This is a platform integration example, not a trading strategy or evidence of trading performance.

Key ideas

  • A chart indicator can request position closure by sending an event to an Expert Advisor.
  • The Expert Advisor must submit the server request because indicators cannot modify positions directly.
  • Closing by position ticket helps target one position, including in hedging accounts.
  • A dedicated close-position event avoids accidentally invoking close-all behavior.
  • The article covers the Expert Advisor changes and defers the full indicator implementation.

Tags

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