Skip to content
All library documents

Managing Positions with Initial Stops, Targets, and Trailing Stops

Article MQL5 code base

Summary

The document explains an Expert Advisor approach to managing positions on the current trading symbol. When enabled, it can add an initial stop loss and take profit to positions that lack either setting. For buy positions, those levels are calculated from the current bid; for sells, they are calculated from the current ask, with the offsets reversed to reflect trade direction. A separate trailing stop applies only while a position is profitable.

A parameter controls whether initial levels are added only to positions where a stop or target is zero. When that condition is disabled, the initial stop and take-profit settings are inactive. The manager applies to every position on the symbol and does not filter by a unique magic number, which can matter when multiple strategies share an instrument. The document outlines behavior and suggests using a strategy tester to observe it, but provides no performance results or detail on trailing-step mechanics, execution costs, or safeguards around modifying positions.

Key ideas

  • Initial stop-loss and take-profit levels can be added to positions that lack either setting.
  • The buy and sell levels are calculated from the relevant current bid or ask, with direction-specific offsets.
  • Trailing logic is active only for profitable positions.
  • The manager operates on all positions for the current symbol without filtering by a unique magic number.
  • The description explains position-management behavior but gives no evidence of strategy performance.

Tags

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