Skip to content
All library documents

Setting Position Stop Losses by Target Account-Currency Loss

Article MQL5 code base

Summary

This script sets a stop loss for each open position so that a hit would produce an approximate loss equal to a specified amount in the account’s currency. It is intended to work across deposit currencies and forex symbols by using the platform’s loss tick value for currency conversion. The target amount is supplied as an input, and the calculated stop price is applied position by position.

Before modifying a position, the script checks broker stop and freeze constraints. It leaves a stop unchanged when it is already within one tick of the calculated target and skips positions where current prices or broker rules make the requested stop invalid, with a reason reported. The description provides no code, examples, or live results. The target is approximate, and the document does not discuss commissions, gaps, execution slippage, or whether a requested loss amount can be guaranteed during fast markets.

Key ideas

  • The script calculates a stop price for each open position from a target loss amount in account currency.
  • It relies on the platform’s loss tick value to account for currency conversion across forex symbols.
  • Broker stop and freeze levels are checked before a modification is sent.
  • Positions with an already suitable stop or an invalid requested stop are skipped.
  • The target loss is approximate and does not guarantee the realized loss at execution.

Tags

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