Skip to content
All library documents

Reversing Trade Direction After a Position Closes at TP or SL

Article MQL5 code base

Summary

This expert-advisor example describes a reversal rule: when a position closes at its take-profit or stop-loss, the program opens a position in the opposite direction. A buy closure is followed by a sell, and a sell closure by a buy. The explanation focuses on detecting closed deals through a trade-transaction event, filtering them by symbol and strategy identifier, and tracking whether a new trade should be placed.

The example also checks whether the requested position size is affordable before submitting an order, and reports the broker response. This is implementation guidance for event-driven order handling, not evidence that the reversal rule is profitable. No market, timeframe, sizing rationale, or performance results are provided. Alternating direction after either exit can create repeated exposure and transaction costs, and the document does not discuss slippage, spread, or safeguards beyond the funds check.

Key ideas

  • The expert advisor reverses trade direction after a position closes at take-profit or stop-loss.
  • Trade transaction events identify qualifying closures by symbol and strategy identifier.
  • The logic tracks closures and entries to control whether another position should be opened.
  • A volume check occurs before order submission to reduce insufficient-funds failures.
  • The document explains implementation mechanics but provides no evidence of strategy profitability.

Tags

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