Gold · XAUUSD · MetaTrader 5
Set your gold rules on your phone. MetaTrader 5 trades them.
Pick a strategy, the risk per trade, a stop loss, the hours and a daily loss limit. Dhahabu writes them into a real Expert Advisor (.mq5) and preset (.set) for any MT5 broker, then keeps the journal and a desk with today’s and this week’s result.
- Writes
- .mq5 + .set
- Brokers
- Any on MT5
- Every trade
- Has a stop loss
Works with Exness, HFM, FXPesa, IC Markets, XM or any MT5 broker, on any gold symbol: XAUUSD, XAUUSDm, GOLD, XAUUSD.pro.
From rules to MQL5
The phone writes the robot.
Every rule you set on the phone becomes an input in a real MetaTrader 5 Expert Advisor. Nothing is hidden: you can read the source, and change any input later from MT5 itself.
- Strategy
- EMA trend, 20 / 50
- Timeframe
- M15
- Risk per trade
- 1% of balance
- Stop loss
- 800 pts · $8.00
- Take profit
- 1,600 pts · $16.00
- Trades per day
- 3 at most
- Daily loss limit
- 3% of the day’s balance
- Max spread
- 40 pts · $0.40
- Hours
- 0 to 24 · all day
- Break-even
- after 600 pts · $6.00
An excerpt. The full source is about 250 lines and compiles in MetaEditor as it is.
//| Dhahabu_Nairobi_Trend.mq5
//| Robot: "Nairobi Trend" · EMA trend · M15
//| Works with any broker: attach it to that broker's gold chart
//| (XAUUSD, XAUUSDm, GOLD ...). Distances are gold points: 100 = $1.00.
//| Every trade carries a stop loss. No robot can guarantee profit.
input group "Risk (lot size follows your balance)"
input double InpRiskPercent = 1.0; // Risk per trade, % of balance
input int InpStopLossPts = 800; // Stop loss, gold points (100 = $1)
input int InpTakeProfitPts = 1600; // Take profit, gold points
input int InpMaxTradesPerDay = 3; // Most trades in one day
input double InpMaxDailyLossPct = 3.0; // Stop for the day after losing this %
input int InpMaxSpreadPts = 40; // Skip when spread is wider (gold points)
// Lots so that hitting the stop loses InpRiskPercent of the balance.
double LotsForRisk(double slDistance, ENUM_ORDER_TYPE type, double price)
{
double risk = AccountInfoDouble(ACCOUNT_BALANCE) * InpRiskPercent / 100.0;
double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE_LOSS);
double lossPerLot = slDistance / tickSize * tickValue;
double lots = MathFloor(risk / lossPerLot / step) * step;
if(lots < minL) return 0; // balance too small for this risk: skip, never over-risk
...
}
void OnTick()
{
...
if(!InSession()) return;
if(DailyLossHit()) { Print("Dhahabu: daily loss limit reached, resting until tomorrow."); return; }
if(TradesToday() >= InpMaxTradesPerDay) return;
if(OpenPositions() > 0) return;
if(spread > Gold(InpMaxSpreadPts)) return;
...
}
Lot size · worked out before every trade
0.02lots
Your balance decides the lot size. Not a guess, not a mood.
- Balance
- $2,000.00
- Risk per trade · 1%
- $20.00 at stake
- Stop loss · 800 points
- $8.00 on the price
- Loss per 0.01 lot at the stop
- $8.00
- Lot size, rounded down
- 0.02 lots · $16.00 at the stop
The balance grows, the lot grows; it shrinks, the lot shrinks. If the balance is too small for even the broker’s minimum lot inside your risk, the trade is skipped rather than over-risked.
Rules that run on every candle
How it protects the account.
Five rules sit between a signal and an order. Each one is an input you set, and each one is checked in the EA’s code before anything is sent to your broker.
- SL
Every trade carries a stop loss
Each order goes to your broker with its stop and target already attached. The robot will not even start if the stop loss is set to zero.
InpStopLossPts - 1%
The lot comes from your balance
Before every trade it reads your balance and your broker’s tick value, then picks the lot that loses your chosen percent if the stop is hit. Rounded down, never up.
InpRiskPercent - 3%
A daily loss limit
When equity falls that far below the day’s starting balance, the robot stops opening trades and rests until tomorrow. A bad day stays one bad day.
InpMaxDailyLossPct - $0.40
A spread filter
Gold spreads widen at rollover and around news. If the spread is wider than you allow, that candle is skipped instead of paying for it.
InpMaxSpreadPts - 1
One position at a time, a cap per day
A robot never stacks trades on top of each other, and it stops after the number of trades you set for the day.
InpMaxTradesPerDay
These rules keep each loss small and stop a bad day from turning into a bad month. They do not stop losses from happening. Some trades will hit the stop.

Hours · 0 to 24, broker server time
24/5
Runs whenever gold is open.
Set the hours to 0–24 and the robot reads every new candle from the Monday open to the Friday close. At weekends gold does not trade, so neither does the robot. Or give it a window — the London morning, say — and it stays quiet outside it.
MT5 has to stay running: a PC left on, or a VPS.
About fifteen minutes, once
Install in 5 steps.
Two steps on the phone, three in MetaTrader 5. After that, changing a rule means loading a new preset, not starting again.
On your phone
- 1
Set up a robot
Choose EMA trend, range breakout or RSI reversion, then the risk per trade, stop loss, take profit, hours and daily loss limit.
- 2
Get the EA file
Open the robot and tap Get EA file. Copy the .mq5 source and the .set preset to the computer that runs MT5.
In MT5, on a PC or VPS
- 3
Compile it
File → Open Data Folder → MQL5 → Experts. Save the .mq5 there, open it in MetaEditor and press Compile.
- 4
Attach it to the gold chart
Open your broker’s gold chart — XAUUSD, XAUUSDm, GOLD — and drag the EA onto it. On the Inputs tab press Load and pick the .set file.
- 5
Turn on Algo Trading and leave MT5 running
The Algo Trading button turns green. Arm the robot on your phone, and log its trades in the journal as they close.
Before real money: run it on a demo account for a few weeks and read the journal.
Plain answers
What people ask first.
Does it work with my broker?
If your broker offers MetaTrader 5 and allows Expert Advisors, yes — Exness, HFM, FXPesa, IC Markets, XM and the rest. The robot trades whatever gold chart you attach it to, so XAUUSD, XAUUSDm, GOLD or XAUUSD.pro all work without editing.
It reads the contract size, price digits and tick value from your broker, so a USD, KES or cent account is sized correctly.
Can it run 24/7?
It can run all day, every day that gold trades: from the Monday open to the Friday close, with the market’s short daily break. Gold is closed at weekends, so the robot is idle then.
It only runs while MetaTrader 5 is open and connected — on a PC you leave on, or on a VPS. If the PC sleeps, the robot sleeps.
Will it only make profit?
No. No robot can promise that, and anyone who does is selling something. Some trades will hit their stop loss, and there will be losing days and losing weeks.
What Dhahabu does is keep each loss to the size you chose, stop for the day at your limit, and keep an honest journal so you can see whether a strategy is working before you trust it with more.
Do I need a PC?
You need MetaTrader 5 for desktop running somewhere, because the MT5 phone app cannot run Expert Advisors. That can be a Windows PC at home or a VPS — a rented computer in a data centre that stays on. Many brokers offer one, and MT5 has its own built-in hosting.
The phone is where you set up robots, get the EA files, watch the desk and keep the journal.
Does the phone place the trades?
No. MetaTrader 5 places every trade, following the robot’s rules. The phone writes the robot, and you log its trades from MT5’s history into the journal to follow today’s and this week’s result.
Can I try it without real money?
Yes, and you should. Open a demo account with your broker, run the robot there for a few weeks, and read the journal. Each MT5 account in the app is marked Demo or Live, so the two never mix.
Where are my robots and trades kept?
In your own private account, which you sign in to. Your robots, journal and MT5 account details are not shared with anyone. The app never asks for your MT5 password.