Skip to content
All library documents

Broker-Aware Gold Contract Detection and Risk-Based Position Sizing

Article MQL5 code base

Summary

This MetaTrader-oriented description explains how to identify a broker’s gold symbol and calculate position size from the symbol’s actual trading specifications. Symbol detection scores candidate names, favors stronger gold matches and excludes other precious metals; an explicit symbol can be attached when naming conventions are unusual. The class reads contract size, precision, tick size and loss value, volume limits and increments, and stop and freeze levels from the trading terminal rather than relying on fixed assumptions.

For risk sizing, it converts a permitted monetary loss and stop distance into volume using the reported loss tick value, then rounds down to the broker’s volume step. If the minimum tradable volume would exceed the risk allowance, it returns zero instead of rounding upward. Diagnostics flag atypical contract details and print a specification report. A worked example demonstrates differing volumes for contracts measured in different ounce amounts while targeting the same loss. The material describes intended functionality and an example, but provides no independent test results; correctness still depends on accurate terminal specifications and suitable stop-distance inputs.

Key ideas

  • Gold symbols and contract specifications vary across brokers, so position sizing should read them from the trading terminal.
  • Risk-based volume calculation uses the loss value per tick and the planned stop distance to estimate potential loss.
  • Rounding volume down to the broker’s permitted step helps keep risk within the chosen budget.
  • Returning zero when minimum volume exceeds the risk allowance avoids silently taking a larger risk than intended.
  • Diagnostic reports can help compare symbol specifications, but the description supplies no independent validation results.

Tags

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