Skip to content
All library documents

Calculating Open-Position Profit and Loss as a Share of Account Balance

Article MQL5 code base

Summary

This document explains a trading-account metric for expressing the current profit or loss on selected open positions as a percentage of account balance. A helper function totals each eligible position’s current profit or loss, commission, and swap. It filters positions by a specified magic number and by whether the position’s symbol matches the chart’s current symbol.

The relative figure is calculated by dividing that total by the account balance, rounding the result to two decimal places, displaying it in a chart comment, and returning it. This provides a compact view of unrealized account exposure for the filtered positions. The description does not define how to handle a zero balance, distinguish drawdown from general unrealized profit or loss, or account for closed trades and broader portfolio exposure. It presents no trading results or validation, so the metric’s interpretation depends on the chosen position filters and denominator.

Key ideas

  • The metric divides selected open positions’ current profit or loss by account balance.
  • The position total includes commission and swap as well as current profit or loss.
  • Only positions matching the configured magic number and the chart’s symbol are included.
  • The result is rounded to two decimal places and displayed on the chart.
  • The calculation does not describe closed trades or total portfolio exposure.

Tags

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