# AURA XAU Scalper EA v2.1.0: Install, Compile, Test Source: `UniversalXAUUSD_M5_Scalper.mq5`. It implements `Universal_XAUUSD_M5_Scalping_EA_Specification.pdf`. **This build is DEMO-ONLY:** `AURA_LIVE_TRADING_ENABLED=false`. If you attach it to a live account, `OnInit` fails, and the backend also refuses live activation. > Status: the EA has **not been compiled** and has **not placed any MT5 trades** yet. The build server is ARM Linux, and MetaEditor/MT5 (x86 Windows programs) cannot run there. Follow the steps below on Windows and keep the evidence listed in section 6. ## 1. What the EA implements (spec mapping) | Spec | Implementation | |---|---| | Completed bars only, once per new M5 bar | `OnTick` new-bar detection; signal uses shift 1 (signal) and shift 2 (previous). The EA waits for the next fresh bar after it is attached. | | Trend M15 EMA50/EMA200 | latest completed M15 bar. It checks that M15 is in sync with the M5 close. | | Pullback | previous M5 candle low <= EMA20 <= high ("touched or crossed") | | RSI 50–68 buy / 32–50 sell (inclusive) | `InpRsi*` | | VWAP | resets 00:00 UTC; M1 typical price x tick volume. **Fails closed** (no trade) if M1 data is missing or covers less than 50% of the day. | | ATR band | ATR(14) of the signal bar must be between the 20th and 90th percentile of the previous 100 completed ATR values (nearest-rank method) | | Entry drift | \|Ask (buy) or Bid (sell) − signal close\| <= 0.25 x ATR, checked again on every retry | | SL / TP | SL = 1.2 x ATR from the **actual fill** (re-set after the fill), TP = 1.8 x SL distance, rounded to tick size. Stop/freeze levels are validated; a stop is never widened or removed to get past a broker restriction | | Time stop | closes the position after 12 completed M5 candles | | Sizing | spec's `CalculateRiskVolume` (OrderCalcProfit, cost reserve, round down only). If the minimum lot would exceed the risk budget, the trade is skipped. Also checks the aggregate volume limit and margin with `OrderCalcMargin`, plus `OrderCheck` | | Duplicate protection | the signal-bar marker is saved **before** `OrderSend` (survives restarts); deal history is checked for this bar; retries are bounded and only for requote/price-changed/price-off, and each retry first checks whether a position already exists | | Exposure | Netting: blocks if *any* position exists on the symbol. Hedging: counts all positions on the symbol (any magic) against the cap; pending-order check | | Risk | 0.25% per trade; daily 1.0% (resets 00:00 UTC daily) and weekly 2.5% (resets Monday 00:00 UTC only) loss cutoffs (equity incl. floating); 8% peak-equity breaker (latched); 4-loss streak lock; 8 entries per day. State is persisted in GlobalVariables and reconciled from deal history on startup | | Spread gate | spread <= min(0.10 x ATR, `InpApprovedSpreadCap` in price units) | | Broker adapter | symbol discovery (stops if ambiguous), filling-mode detection, tick-value cross-check with OrderCalcProfit (±10%, otherwise no trading), metadata logged at start and whenever it changes | | Permissions | terminal connected, algo trading, EA, account and expert permissions; symbol full-access mode; broker trade session; stale quote > 30 s | | Logging | structured CSV `MQL5\Files\AURA_XAU_.csv` + Experts tab + backend `/api/ea/log` (rate-limited) | | Licence | activate, then licence check every 5 min. If the backend is unreachable, new entries continue for a 30-min grace period and are then blocked. A revoked or expired licence blocks new entries immediately. Open positions keep their server-side SL/TP, and the time stop keeps running | ## 2. UNAPPROVED defaults: NOT owner-approved conditions The PDF does not define the 5 rules below. The owner skipped the question, so they are **defaults chosen by the developer** and are **not approved trading conditions**. Confirm or change each one before any evaluation. The EA logs `config_unapproved_defaults` at every start. | # | Topic | PDF says | Default in code | Inputs to change | |---|---|---|---|---| | A1 | Session windows | "configured liquid London and New York windows", DST-aware | London 08:00–12:00 London time; New York 08:30–12:00 New York time; Mon–Fri | `InpLondonStartMin/EndMin`, `InpNewYorkStartMin/EndMin` (minutes from local midnight) | | A2 | News source | high-impact USD ±15 min; fail closed if feed missing/stale | Live/demo: MT5 built-in calendar (USD, HIGH importance). No USD events in last 7 days = stale = no new entries. Tester: `Common\Files\AURA_USD_high_impact_utc.csv`; missing file = no trades | `InpNewsWindowMinutes`, `InpTesterNewsFile` | | A3 | Rollover / weekly close | "block around rollover, near weekly close" | Block 16:30–17:30 New York; block after Friday 16:00 New York | `InpRolloverBlockMin`, `InpFridayCloseBlockMin` | | A4 | Unconfirmed protection | "documented emergency response" | 3 attempts to attach SL/TP, then close the position at market | code (`EnsureProtected`) | | A5 | Loss-streak / peak-breaker resume | "stop after 4 losses; require review" | Locks stay until the customer clicks "I have reviewed" on the dashboard; the EA clears them at its next licence check (≤5 min). Never clears in Strategy Tester | dashboard | Other implementation choices (smaller, also not in the PDF): ATR percentile uses the nearest-rank method; previous candle "touched or crossed" = low ≤ EMA20 ≤ high of that candle; VWAP needs ≥50% M1 coverage since 00:00 UTC; stale quote = 30 s; tester server time zone default = UTC+2/+3 with US DST. ## 2a. Units and costs (must be configured per broker) - **`InpApprovedSpreadCap` is in PRICE units** (Ask − Bid in USD per ounce). It is **not** points and **not** pips. 0.35 = $0.35 = 35 points on a 2-digit gold quote (e.g. 2400.12) or 350 points on a 3-digit quote (2400.123). "Pips" is not used anywhere because brokers define gold pips differently. The EA logs the conversion at start (`config spread_cap=… price = … points`). The effective gate is `spread ≤ min(0.10 × ATR, cap)`. 0.35 is a placeholder; set your broker's approved value. - **`InpCostReservePerLot` is REQUIRED**: your broker's round-trip commission + fees for 1.0 lot, in the account deposit currency (e.g. $7 per side = 14). While it is 0, **new entries are blocked** (`cost_reserve_not_configured`). `InpAllowZeroCostReserve=true` exists only for preliminary code tests, as the spec allows; any results from such runs are misleading. At start the EA logs `measured_costs` (commission + fees per lot from the last 90 days of deals on the symbol) and warns if your input is lower. - Swap is not reserved upfront (positions close within 12 M5 candles). It is recorded from actual deals. ## 2b. Reset schedule (UTC, independent of broker server time) | Limit | Baseline (equity incl. floating) taken at | Resets | |---|---|---| | Daily loss 1.0% + daily entry count (8) | first tick/timer after **00:00 UTC every day** | every day | | Weekly loss 2.5% | **Monday 00:00 UTC** | **once per week only**, never daily | | Peak-equity 8% breaker | running peak | only after a dashboard review (A5) | | Loss streak (4) | — | only after a dashboard review (A5) | On the first start the baselines are the equity at that moment. All values persist across terminal restarts (MT5 GlobalVariables). ## 3. Compile (Windows) 1. Install MetaTrader 5 from your broker, open a **demo** account, then File → Open Data Folder. 2. Copy `UniversalXAUUSD_M5_Scalper.mq5` into `MQL5\Experts\`. 3. Open it in MetaEditor (F4) and press **F7**. Expected result: `0 errors`. Save a screenshot of the Errors/Journal tab. 4. If there are errors, copy the full Errors tab text and send it to me. ## 4. Strategy Tester (no WebRequest; licence bypass is for the tester only) 1. Put a news CSV in `%APPDATA%\MetaQuotes\Terminal\Common\Files\AURA_USD_high_impact_utc.csv` (one `YYYY.MM.DD HH:MM` UTC time per line). 2. Set `InpCostReservePerLot` to your broker round-trip commission per lot and `InpApprovedSpreadCap` (price units). Tester: Expert = AURA, symbol = your gold symbol, period M5, Modelling **Every tick based on real ticks**, delay realistic, deposit/currency as your account. 3. Run 2024 first (validation). Save the report HTML + the `AURA_XAU_*.csv` log from the tester agent's `MQL5\Files`. 4. Check the log for `signal`, `order_send`, `position_protected`, `deal`, and the time-stop closes. Also check that there are no two `order_send` entries for the same bar. ## 5. Demo forward test on live market prices (real connection) **Machine:** a Windows 10/11 PC or Windows VPS that stays on 24/5 (a VPS near your broker's server is best). The EA only trades while MT5 is running and connected. ### 5.1 Demo account 1. Install your broker's MT5 terminal and open a **DEMO** account (File → Open an Account). Live trading stays disabled: the EA refuses live accounts and the backend refuses live activation. 2. Log in. Bottom right should show a ping and no "No connection". In the Navigator, the account must say "Demo". ### 5.2 Verify the broker symbol, spread units and commission 1. Market Watch → right-click → Symbols → find gold (e.g. `XAUUSD`, `XAUUSD.m`, `GOLD`). If more than one exists, put the exact name in `InpSymbol`. 2. Right-click the symbol → **Specification**. Write down: Digits, Contract size, Tick size, Volume min/step/max, Stops level, Freeze level, Filling, Execution mode, Trade mode ("Full access" required). 3. **Spread units:** in Market Watch, enable the Spread column (shown in **points**). Convert to price: price = points × 10^−Digits (Digits=2 → 35 points = 0.35; Digits=3 → 350 points = 0.35). Decide your approved cap in **price** and set `InpApprovedSpreadCap`. 4. **Commission:** take it from your broker's account-type page, or open and close 0.01 lot once manually *before* attaching the EA and read the commission in History → Deals. Round-trip per 1.0 lot = |entry commission + exit commission| ÷ volume. Set `InpCostReservePerLot` to that value (account currency). The EA logs `measured_costs` and the dashboard shows "Measured commission / lot". If the reserve is lower, the dashboard shows a red warning. ### 5.3 Compile Section 3 above. You need 0 errors. If there are errors, send me the full Errors tab text and I will fix the code. Do not skip this step. ### 5.4 Algo Trading + WebRequest 1. Tools → Options → **Expert Advisors**: tick **Allow algorithmic trading** and **Allow WebRequest for listed URL**, then add `https://connectx.website` (it must match `InpBackendURL` exactly). 2. On the toolbar, the **Algo Trading** button must be green. ### 5.5 Attach the EA 1. On the website: Dashboard → **Start 14-day demo trial** → copy the activation token. 2. Open a chart of the gold symbol (any timeframe), then drag the EA from Navigator → Expert Advisors. 3. Common tab: tick "Allow Algo Trading". Inputs: `InpActivationToken`, `InpBackendURL`, `InpSymbol` (if needed), `InpCostReservePerLot`, `InpApprovedSpreadCap`. Leave the strategy inputs at their spec defaults. **Do not** disable the session/news filters, and do not change anything to force a trade. 4. Chart top right: EA name with a blue/smiling cap icon. Experts tab: `init`, `symbol_spec`, `config spread_cap=…`, `measured_costs`, `activate http=200`. ### 5.6 Confirm a real heartbeat Within about 30 s the dashboard shows **Demo connected**, and the risk card shows broker settings that only a real terminal reports: MT5 build, digits/point, live spread in points, your exact symbol name, and your masked account number and broker server. They must match what you see in MT5. If they don't, it is not your terminal. ### 5.7 Let it run, no forced trades - Trades happen only when all spec conditions are true inside the session windows. Several hours or days with no trade are normal. The risk card always shows the current reason entries are blocked (e.g. `outside_session`, `news_window`, `spread_gate`). - When a valid signal fires, the Experts tab / CSV shows `signal BUY|SELL …` → `order_send … retcode=10009` → `position_protected … sl=… tp=…` → later `deal` (exit by SL, TP or `time_stop`). - Verify SL/TP: in MT5 Trade tab, the position shows S/L and T/P. SL distance ≈ 1.2 × ATR from the open price, TP distance = 1.8 × the SL distance. ## 6. Evidence to collect (send it back to me) 1. **Compile:** MetaEditor screenshot showing `0 errors` + the EA version 2.1.0 line. 2. **Connection:** MT5 screenshot (Navigator showing a Demo account, green Algo Trading, EA on chart) + dashboard screenshot showing *Demo connected* and the broker settings section. 3. **Trade history:** MT5 History → Positions/Deals for the EA's tickets (comment starts with `AURA`), with open/close price, S/L, T/P and commission. 4. **EA logs:** the file `MQL5\Files\AURA_XAU_.csv` (File → Open Data Folder) + an Experts tab export covering the same period. 5. **Dashboard:** open and closed trades showing the same ticket numbers as MT5. Send the files or screenshots here. I will check each ticket's signal conditions, SL/TP distances, risk sizing and duplicate protection against the log. ## 7. Failure tests (please run on demo) - Remove the URL from the WebRequest list → log shows `webrequest_blocked`; no new entries once the grace period expires. - Revoke the licence in admin → `licence_invalid_revoked`; open position keeps its SL/TP. - Turn off Algo Trading → `algo_trading_disabled_in_terminal`. - Restart the terminal while a position is open → `reconcile open_ours=yes`; no duplicate entry; the time stop still closes it. - Attach to a live account → init fails with "DEMO-ONLY". ## Risk disclosure No backtest has been run. Trading leveraged gold CFDs can lose all deposited capital. No profit guarantee.