Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

Gold Position Size Calculator (XAUUSD) - indicator for MetaTrader 5

Views:
49
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Gold Position Size Calculator (XAUUSD) is a free risk management indicator for MetaTrader 5, designed specifically for gold traders.

The idea

Most retail gold traders lose money not because of bad entries, but because of wrong position sizes. Risking a fixed lot size on XAUUSD means every trade carries a different, unknown risk. This indicator applies the classic risk-based position sizing formula:

Lot size = (Balance x Risk %) / (Stop distance in points x Tick value per lot)

so that if the stop-loss is hit, the loss equals exactly the chosen percentage of the account - no more, no less.

How it works

1. Attach the indicator to a Gold (XAUUSD) chart. It works on any timeframe.
2. Set your account balance and risk per trade (%).
3. Enter your entry price (or leave 0 to use the current price) and your stop-loss price.
4. Optionally set a take-profit price.
5. Read the calculated lot size from the panel - that is the position size that risks exactly your chosen % if the stop is hit.

The panel shows: balance, risk %, risk amount, stop distance in points, calculated lot size, risk/reward ratio and potential profit. Entry, stop-loss and take-profit lines are drawn directly on the chart.

Gold Position Size Calculator on XAUUSD H1 chart

External variables (inputs)

InpAccountBalance - account balance used in the calculation
InpRiskPercent - risk per trade in percent of the balance
InpEntryPrice - planned entry price (0 = current close)
InpStopPrice - stop-loss price (0 = not set)
InpTakeProfit - take-profit price (0 = not set)
InpContractSize - contract size per 1.00 lot (0 = read automatically from the symbol specification)
InpShowLines - show or hide entry, stop and TP lines
InpShowPanel - show or hide the info panel
InpPanelCorner - panel corner

Notes

- Contract size is read automatically from the broker's symbol specification, so the indicator works on XAUUSD, XAUUSDm, gold futures and any other instrument without manual setup.
- The math is non-repainting: values are recalculated only when inputs change or a new bar opens.
- This is a risk calculation tool, not a signal service: it does not open trades and does not promise profits.

A Pro version with one-click execution, break-even, trailing stop and partial close is in development.

Unified Hull MA (4 Lines, Color-Coded, Ring Buffer) Unified Hull MA (4 Lines, Color-Coded, Ring Buffer)

Hull Moving Average indicator displaying four periods on a single chart, colour-coded by direction (green for rising, red for falling, grey for flat). Implemented with a ring buffer and incremental running-sum math, so memory and CPU use remain constant regardless of chart history length. Buffer layout is documented and stable, making the indicator suitable for use with iCustom() from EAs. Supports 2, 3, or 4 Hull lines depending on configuration.

Prop Firm Daily Drawdown Visualizer (Free) Prop Firm Daily Drawdown Visualizer (Free)

Protect Your Funded Account with Institutional-Grade Risk Monitoring. The #1 reason traders fail prop firm challenges is not a bad strategy; it is breaching daily drawdown limits. The AlphaQuant Prop Firm Daily Drawdown Dashboard is a free, high-visibility Expert Advisor

SMC Gold: Liquidity Sweep and Order Block EA for XAUUSD M15 SMC Gold: Liquidity Sweep and Order Block EA for XAUUSD M15

An intraday Smart Money Concepts EA for gold. It waits for price to sweep a recent swing high or low, confirms the reversal with a close through the sweep candle's body, and trades only with the H1 trend. Backtested on XAUUSD M15 over 2025 and 2026 at 1% risk per trade.

Asian Range Sweep Indicator with a Built-In Win Rate Scorecard Asian Range Sweep Indicator with a Built-In Win Rate Scorecard

Marks the Asian session range, signals when London or New York sweeps one side of it and reverses, and keeps a scorecard of how every past signal ended in R, spread included. Non-repainting, with buffers ready for an Expert Advisor.