Skip to content
All library documents

Managing Symbol Positions with Virtual Stops and Trailing Logic

Article MQL5 code base

Summary

This document describes an expert advisor that manages open positions for the chart symbol on which it runs. It monitors position profit and loss against configured take-profit and stop-loss levels, then closes positions at market when a threshold is reached. Those stop and target levels are monitored by the program rather than placed as broker-side orders. The advisor can also apply trailing logic, which does set a stop-loss level, and zero-valued inputs disable individual controls.

The advisor acts on every position for the symbol regardless of its magic identifier, while preserving each position’s magic value before trading operations. When run in the strategy tester, it attempts to open a one-lot buy position during initialization without checking whether the operation succeeded. These details matter for understanding its scope and behavior, but the document provides no performance results or risk analysis. Because the primary stop and target conditions rely on the program running and closing at market, execution may differ from a broker-held protective order.

Key ideas

  • The advisor monitors all positions for the chart’s symbol, without filtering by magic identifier.
  • Configured stop and target thresholds trigger market closures rather than broker-side stop or limit orders.
  • Trailing logic can set a stop-loss level, and zero disables an individual input control.
  • In the strategy tester, initialization attempts a one-lot buy without checking the result.
  • The description contains no evidence about trading performance or execution reliability.

Tags

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