Join our fan page
- Published by:
-
Ali Akbar
Hi, I'm Ali. 24 years old, trading for around 5 years, and developing MQL5/MQL4 tools. I mainly work on automating manual strategies, fixing broken EA logic, and building clean indicators. I care more about clean architecture and proper risk management than over-complicated code. Always down to talk - Views:
- 61
- Rating:
- Published:
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
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.
Where this EA came from
A few weeks ago I published an SMC liquidity sweep scalper that kept a win-rate record for each of its setups. It did well on a couple of forex pairs and badly on others. A few people asked how it does on gold, so I finally tested it on XAUUSD properly.
The first run scared me. On M15 it took 107 trades and hit a 78% drawdown with risk set to 1%. It took me a while to find the reason. On the MetaQuotes-Demo server, SYMBOL_TRADE_TICK_VALUE for XAUUSD comes back as 0.10, but one point on one lot is really worth 1.00. My lot formula trusted that number, so every trade risked about 10% of the balance instead of 1%. OrderCalcProfit() returns the correct value, so SMC Gold asks the server with that function instead. If you size lots from the tick value in your own EAs, check what it says on gold.
Once the sizing was fixed I tested every timeframe from M1 to H1. M1 and M5 lost money on gold in 2026 (profit factor 0.90 and 0.91) because the spread eats too much of a small stop. H1 gave only 15 trades in almost nine months. M15 gave the steadiest result: positive in 2026, and positive again when I checked it on 2025 data. So this version is built for XAUUSD M15 and nothing else.
How it trades
- On every new M15 bar the EA confirms swing highs and lows with a 5 bar lookback on each side. Only closed bars are used, so nothing repaints.
- A sweep is a bar whose wick goes past the last swing by at least 0.15 ATR and then closes back on the other side of it. That is the stop hunt.
- The body of that sweep bar becomes the order block. When the H1 price is above its 50 EMA only sweeps of a swing low (buy setups) are kept. Below the EMA only sweeps of a swing high (sell setups) are kept.
- Within the next 3 bars a candle has to close through the order block, and its range must be at least 0.3 ATR. If that doesn't happen the setup is dropped.
- The entry is at market. The stop goes 0.1 ATR beyond the sweep wick and the target is 2 times the stop distance.
It holds one position at a time. There is no grid, no martingale and no averaging down.
Some parts are there because gold punished me for leaving them out. The order goes out without SL and TP, and the stops are attached to the real fill price right after. If they can't be attached the position is closed at once, so it never runs without a stop. There are no entries in the last 15 minutes before the symbol's trading session ends, because the old version kept getting "market closed" rejections just after 23:00 server time. The spread limit is 60 points. The old limit of 25 blocked almost every setup from July 2026 onward, when the demo spread for gold sat between about 30 and 50 points.
Test settings
| Setting | Value |
|---|---|
| Symbol and timeframe | XAUUSD M15 |
| Server | MetaQuotes-Demo |
| Deposit and leverage | 10,000 USD, 1:100 |
| Risk | 1% of balance per trade |
| Execution | Random delay |
| Modelling, 2026 | Every tick based on real ticks, 99% history quality |
| Modelling, 2025 | Every tick generated from M1 (real ticks were not available for 2025) |
| Inputs | All defaults |
Results
| 2025.01.01 to 2025.12.31 | 2026.01.01 to 2026.09.20 | |
|---|---|---|
| Total trades | 175 | 127 |
| Net profit | 1,397.72 | 861.85 |
| Gross profit | 13,430.47 | 9,177.20 |
| Gross loss | -12,032.75 | -8,315.35 |
| Profit factor | 1.12 | 1.10 |
| Expected payoff | 7.99 | 6.79 |
| Win rate | 36.57% (64 of 175) | 37.01% (47 of 127) |
| Average win | 209.85 | 195.26 |
| Average loss | -108.40 | -103.94 |
| Largest loss | -140.82 | -384.03 |
| Max equity drawdown | 10.47% (1,219.06) | 10.63% (1,187.52) |
| Max consecutive losses | 9 (-1,026.32) | 7 (-736.79) |
| Recovery factor | 1.06 | 0.73 |
| Sharpe ratio | 1.90 | 1.56 |
| Long trades (won) | 107 (40.19%) | 68 (35.29%) |
| Short trades (won) | 68 (30.88%) | 59 (38.98%) |
| Average holding time | 5 h 12 min | 5 h 58 min |
Fig. 1. Balance curve, XAUUSD M15,2026.01.01 to 2026.09.20, real ticks
Fig. 2. Balance curve, XAUUSD M15, 2025,generated ticks
What these numbers mean
The edge is thin. An average win is about 1.9 times an average loss, so the EA needs to win roughly 34 to 35% of its trades just to break even (34.1% in 2025, 34.7% in 2026). It won 36.6% and 37.0%. That is only two or three points above breakeven. MetaQuotes-Demo charges no commission, so if your broker charges one, run the tester with it before anything else. A wider spread or a commission could take most of this margin away.
Losing streaks are part of the deal. With a win rate near 37%, nine losses in a row (2025) cost about 10% of the account. The 2026 curve in Fig. 1 also spent a long stretch, most of the trades between roughly 28 and 63, going sideways and down before it recovered. If that would make you switch it off halfway, this EA is not for you.
The worst trade in 2026 was a buy on 4 September. Its stop was at 4460.86, but it closed at 4430.25 at 15:30 server time, which is when the US jobs report was due that Friday. That's about 30 dollars of slippage on gold and roughly three and a half times the planned loss. The EA has no news filter because the economic calendar doesn't work in the strategy tester, so I had no way to test one. If you run it live, I'd pause it around NFP, CPI and FOMC.
Positions can also stay open over the weekend. The longest one lasted 63 hours in 2026 and 89 hours in 2025, and a Monday gap can be bigger than the stop.
Things I tried that did not make it
A break-even stop at 1R looked good in 2026 (profit factor up from 1.10 to 1.14) and bad in 2025 (down from 1.12 to 1.02). It is still in the inputs but switched off by default.
A longer swing lookback, an H4 trend filter and a stricter sweep size all looked better on January to June 2026 and then did worse on July to September. One example on M5: a 20 bar lookback gave a profit factor of 1.49 in the first half and 0.44 in the second. That is curve fitting, so I kept the original values.
I also built a separate version that traded sweeps of the Asian session range and the previous day's high and low. In 2025 it reached a profit factor of 1.18 to 1.39, but on only 21 to 31 trades. In 2026 it lost money with every setting I ran, so I didn't publish it.
Inputs
| Input | Default | What it does |
|---|---|---|
| InpSwingLookback | 5 | Bars on each side that confirm a swing high or low |
| InpConfirmBars | 3 | Bars allowed for the confirmation close |
| InpATRPeriod | 14 | ATR period used by every distance below |
| InpMinSweepATR | 0.15 | How far the wick must pass the swing, in ATR |
| InpSLBufferATR | 0.10 | Stop distance beyond the sweep wick, in ATR |
| InpMinSLATR | 0.50 | Setups with a tighter stop than this are skipped |
| InpMinConfirmATR | 0.30 | Minimum range of the confirmation candle, in ATR |
| InpUseTrendFilter | true | Trade only with the higher timeframe trend |
| InpTrendTF | H1 | Trend timeframe |
| InpTrendEMA | 50 | Trend EMA period |
| InpRiskPercent | 1.0 | Risk per trade, % of balance |
| InpRewardRatio | 2.0 | Target as a multiple of the stop |
| InpBreakEvenAtR | 0.0 | Break-even trigger in R, 0 switches it off |
| InpMaxSpreadPoints | 60 | No entry above this spread |
| InpMinSLToSpread | 3.0 | The stop must be at least this many spreads wide |
| InpSlippagePoints | 30 | Allowed slippage in points |
| InpMagic | 554001 | Magic number, change it if you run several copies |
| InpUseHours | false | Optional server time window for new setups |
| InpStartHour / InpEndHour | 7 / 20 | That window, used only when InpUseHours is true |
Before you run it
Attach it to an XAUUSD M15 chart. That's the only combination I tested properly. For the record, it also runs without errors on EURUSD H1, the pair MQL5 uses for its automatic check (50 trades from January 2025 to September 2026, profit factor 1.08), but I don't trade it there.
Check your broker's gold spread first. If it stays above 60 points most of the day, the EA will skip most setups. Then give it a month or two on a demo account before you put real money on it. All of the numbers above come from one broker's data over about 21 months. They show how the logic behaved in that period and nothing more.
Ali Rajput
Gold Position Size Calculator (XAUUSD)
Free risk-based position size calculator built specifically for Gold (XAUUSD). Enter your account balance, risk percentage, entry price and stop-loss price - the indicator calculates the exact lot size, risk amount, stop distance, risk/reward ratio and potential profit, and draws entry, stop and take-profit lines on the chart. Contract size is read automatically from the symbol specification, so it works on any gold symbol without manual setup.
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.
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.
MACD Signals
Indicator edition for new platform.

