Schau, wie man Roboter kostenlos herunterladen kann
Finden Sie uns auf Facebook!
und werden Sie Mitglied unserer Fangruppe
Interessantes Skript?
Veröffentliche einen Link auf das Skript, damit die anderen ihn auch nutzen können
Hat Ihnen das Skript gefallen?
Bewerten Sie es im Terminal MetaTrader 5
Expert Advisors

Asia Range Breakout - Learning Template for XAUUSD - Experte für den MetaTrader 5

Istvan Gyarfas
Istvan Gyarfas
  • MQL5 Developer | Gold EAs (XAUUSD) in  Gyafy Trading-Bots
  • Ungarn
  • 419
Ich entwickle Expert Advisors in MQL5, Schwerpunkt Gold (XAUUSD).
Meine Regeln für jeden Bot:
- festes Risiko pro Trade in %, Stop-Loss bei jedem Trade
- kein Martingale, kein Grid, kein Averaging
- Tagesverlust-Limit und Drawdown-Stopp eingebaut
Ansichten:
12
Veröffentlicht:
MQL5 Freelance Benötigen Sie einen Roboter oder Indikator, der auf diesem Code basiert? Bestellen Sie ihn im Freelance-Bereich Zum Freelance

This Expert Advisor is a learning template. The code is short and every step is commented, so you can understand how a complete trading robot works and use it as a starting point for your own ideas.

Strategy

  1. From 02:00 to 10:00 server time the EA records the high and low of the M5 candles (the "Asian range").
  2. At 10:00 it places a Buy Stop above and a Sell Stop below the range (+5 pips buffer).
  3. Only in the direction of the daily trend: buys above the D1 EMA 200, sells below it.
  4. When one order is filled, the other one is deleted (OCO).
  5. Stop loss = opposite side of the range, take profit = 2 x stop loss.
  6. Unfilled orders are deleted at 15:00, open positions are closed at 22:00.

Maximum one trade per day. Ranges smaller than 50 or larger than 400 pips are skipped.

Risk management

  • Lot size calculated from risk % per trade (default 1%)
  • Trade is skipped if the minimum lot would exceed the risk too much
  • Daily loss limit (default 2%) - pause until the next day
  • Drawdown stop from equity peak (default 15%)
  • Spread filter
  • Trades on demo accounts only by default (input InpAllowLiveAccount)

What you can learn from the code

  • Calculating a time-based range from candle data
  • Pending orders (Buy Stop / Sell Stop) with SL and TP
  • OCO logic with OnTradeTransaction
  • Lot sizing by risk percent using tick value and tick size
  • Daily loss limit and drawdown protection
  • Trend filter with an indicator handle (iMA + CopyBuffer)

Inputs

Input Default Meaning
InpRiskPercent 1.0 Risk per trade in % of balance
InpMaxDailyLossPercent 2.0 Max. daily loss in % (0 = off)
InpMaxDrawdownPercent 15.0 Max. drawdown from equity peak in % (0 = off)
InpRangeStartHour / InpRangeEndHour 2 / 10 Time window of the range (server time)
InpTradeEndHour / InpCloseHour 15 / 22 Delete pending orders / close position
InpBufferPips 5 Buffer above/below the range
InpTakeProfitR 2.0 Take profit as multiple of the SL distance
InpMinRangePips / InpMaxRangePips 50 / 400 Allowed range size
InpUseD1Filter / InpD1EmaPeriod true / 200 Daily trend filter
InpMaxSpreadPips 10 Maximum spread for new orders
InpAllowLiveAccount false Allow trading on a live account

Backtest

XAUUSD M5, 01.01.2024 - 25.11.2026, initial deposit 3000 USD, default inputs: profit factor 1.59, 227 trades, 54.6% winners, max. equity drawdown 7.85%. History quality of this test: 32% real ticks. Note: 211 of 227 trades were buys because gold was in a strong uptrend during this period. Between Nov 2024 and Jul 2025 the equity moved sideways to slightly down.

Balance curve of the backtest (XAUUSD M5, 2024-2026)

Balance curve of the backtest (XAUUSD M5, 2024-2026)

Test results with default inputs

Test results with default inputs

Settings

Use on XAUUSD, timeframe M5. All times are broker server time - check your broker's time zone and adjust the hours if needed.

Disclaimer

For educational purposes only. Not financial advice. Past backtest results do not guarantee future results. Test on a demo account first.

ChangePoint: Bayesian online change point detection ChangePoint: Bayesian online change point detection

Online-Erkennung von Veränderungen des Mittelwerts oder der Volatilität (Adams-MacKay): Wahrscheinlichkeit einer Veränderung in den letzten k Balken, aktuelle Segmentlänge, Prognose und ein Indikator.

Copula: Gaussian, Student t, Clayton, Gumbel and Frank copulas with tail dependence Copula: Gaussian, Student t, Clayton, Gumbel and Frank copulas with tail dependence

Passt fünf bivariate Copulas auf Rangzahlen an, unter Berücksichtigung von Kendalls Tau, der Abhängigkeit der Randverteilungen, der Wahrscheinlichkeit gemeinsamer Extremtage, des AIC sowie der bedingten Wahrscheinlichkeiten des Paarehandels.

Accumulation/Distribution Accumulation/Distribution

Der Accumulation/Distribution Indikator wird aus Änderung von Preis und Volumen bestimmt.

Accelerator Oszillator (AC) Accelerator Oszillator (AC)

Der Acceleration/Deceleration Indikator (AC) misst die Beschleunigung und Verlangsamung des aktuellen Marktimpulses, der Kraft der Kursbewegung.