# NANDR ORB + Order Block EA A MetaTrader 5 Expert Advisor for scalping **XAUUSD (Gold/USD)** on **M15** (also supports M5 and M1), combining two strategies: - **Opening Range Breakout (ORB)** — tracks the high/low of the first 15 real minutes of each trading session and trades confirmed breakouts + retests - **Order Block Detection** — identifies institutional order blocks using volume pivot analysis (LuxAlgo methodology) and uses them as trade confirmation and SL anchors --- ## Strategy Logic ### Opening Range Breakout 1. At the start of each enabled session, accumulate the **ORB High** and **ORB Low** over the first 15 real-time minutes 2. Detect a **confirmed breakout** using a strict N-bar filter (no false breaks) 3. Wait for price to **retest** the broken ORB level 4. Enter on the retest ### Order Block Confirmation - A **volume pivot** is identified where the bar at index `[length]` has the highest volume in a symmetric window - Market structure determines direction: bullish OB if the pivot was a swing low, bearish OB if a swing high - **Bullish OB zone**: `[low, hl2]` of the pivot bar - **Bearish OB zone**: `[hl2, high]` of the pivot bar - OBs are removed (mitigated) when price penetrates the zone Entry is taken when the ORB retest aligns with a nearby Order Block (optional — configurable). --- ## Timeframe Scaling The ORB window is always **15 real minutes** regardless of chart timeframe: | Timeframe | ORB Bars | Breakout Confirm | OB Pivot Length | |-----------|----------|-----------------|-----------------| | **M15** (default) | 1 | 2 bars | 5 | | M5 | 3 | 3 bars | 5 | | M1 | 15 | 5 bars | 10 | All values auto-configured by timeframe and individually overrideable via inputs. --- ## Sessions All sessions are **disabled by default** — enable the ones you want to trade: | Session | UTC Start | Best for XAUUSD | |---------|-----------|-----------------| | Daily Open | 00:00 | Asian range setup | | Tokyo | 00:00 | Low volume, range-bound | | London | 07:00 | High volatility ✓ | | NY | 12:00 | High volatility ✓ | | NY ORB (Stock open) | 13:30 | Strong momentum ✓ | --- ## Input Parameters ### Symbol Settings | Parameter | Default | Description | |-----------|---------|-------------| | `InpSymbolName` | `XAUUSD` | Symbol base name — auto-detected from broker (supports XAUUSD, XAUUSD.s, XAUUSD_, etc.) | ### Timeframe Settings | Parameter | Default | Description | |-----------|---------|-------------| | `InpOrbTimeframe` | `M15` | Chart timeframe for ORB (M1 / M5 / M15) | | `InpBreakoutConfBars` | `0` | Breakout confirmation bars — `0` = auto by TF | ### Session Settings | Parameter | Default | Description | |-----------|---------|-------------| | `InpUseDailyOpen` | `false` | Enable Daily Open session | | `InpUseTokyoSession` | `false` | Enable Tokyo session | | `InpUseLondonSession` | `false` | Enable London session | | `InpUseNYSession` | `false` | Enable NY session | | `InpUseNYOrbSession` | `false` | Enable NY ORB session (13:30 UTC) | ### Order Block Settings | Parameter | Default | Description | |-----------|---------|-------------| | `InpOBPivotLength` | `0` | Pivot window length — `0` = auto by TF | | `InpOBMaxCount` | `5` | Max active OBs stored per direction | | `InpOBMitig` | `Wick` | Mitigation method: Wick or Close | | `InpOBRequireConf` | `false` | Require OB near entry to take trade | | `InpOBProximityPips` | `50` | Distance in pips to consider OB "nearby" | ### Entry Settings | Parameter | Default | Description | |-----------|---------|-------------| | `InpEntryMode` | `Market` | Market order on retest close, or Limit at ORB level | | `InpUseStrictFilter` | `true` | Strict N-bar breakout filter (recommended) | ### Lot Size & Risk | Parameter | Default | Description | |-----------|---------|-------------| | `InpLotMode` | `Risk %` | Fixed lot or auto-calculated from risk % | | `InpFixedLotSize` | `0.01` | Fixed lot (used when LotMode = Fixed) | | `InpRiskPercent` | `1.0` | % of balance to risk per trade | ### Stop Loss | Parameter | Default | Description | |-----------|---------|-------------| | `InpSLMode` | `OB Boundary` | SL placement: OB Boundary / Fixed Pips / ATR-based | | `InpSLPips` | `20.0` | SL in pips (Fixed mode) | | `InpATRMultiplier` | `1.5` | ATR multiplier for SL (ATR mode) | | `InpATRPeriod` | `14` | ATR period | ### Take Profit | Parameter | Default | Description | |-----------|---------|-------------| | `InpTPMode` | `RR Ratio` | TP by fixed pips or Risk:Reward ratio | | `InpTPPips` | `40.0` | TP in pips (Fixed mode) | | `InpRRRatio` | `2.0` | Risk:Reward ratio (RR mode) — 2.0 = 1:2 | ### Trade Management | Parameter | Default | Description | |-----------|---------|-------------| | `InpBreakevenTrigPips` | `15.0` | Move SL to breakeven when profit reaches this | | `InpBreakevenOffPips` | `2.0` | Breakeven SL offset above/below entry | | `InpTrailingStopPips` | `0.0` | Trailing stop distance — `0` = disabled | | `InpMaxTradesPerDay` | `3` | Max trades opened per calendar day | | `InpMaxPosPerSession` | `1` | Max simultaneous positions per session | ### Risk Management | Parameter | Default | Description | |-----------|---------|-------------| | `InpMaxDailyLossUSD` | `0.0` | Halt trading if daily loss exceeds this USD amount — `0` = off | | `InpMaxDailyLossPct` | `0.0` | Halt trading if daily loss exceeds this % of equity — `0` = off | ### Display Settings | Parameter | Default | Description | |-----------|---------|-------------| | `InpShowDashboard` | `true` | Corner stats panel | | `InpShowORBLines` | `true` | ORB High/Low/Mid lines on chart | | `InpShowOBZones` | `true` | Order block rectangles on chart | | `InpShowTradeLabels` | `true` | Entry arrows and SL/TP lines on chart | --- ## Dashboard A real-time HUD is drawn in the top-left corner showing: ``` ▌ NANDR ORB+OB EA ───────────────────────── Symbol : XAUUSD TF: M15 OrbTF : M15 BarsNeeded: 1 ───────────────────────── London H:2685.50 L:2672.30 [BULL↑] NY H:2690.10 L:2681.00 [ARMED] ───────────────────────── BullOBs: 2 BearOBs: 1 ───────────────────────── Trades : 1 / 3 W/L : 1 / 0 WR: 100% Today PnL: +48.20 USD Equity : 10048.20 ``` --- ## Chart Visuals | Object | Color | Description | |--------|-------|-------------| | ORB High/Low lines | Session color | Solid horizontal lines at ORB levels | | ORB Mid line | Session color (dotted) | Midpoint of ORB range | | Bullish OB zone | Green rectangle | Active bull order block | | Bearish OB zone | Red rectangle | Active bear order block | | Entry arrow | Green (buy) / Red (sell) | Trade entry marker | | SL line | Red dashed | Stop loss level | | TP line | Green dashed | Take profit level | Session line colors: **Tokyo** = Blue · **London** = Red · **NY / NY ORB** = Gold · **Daily** = Silver --- ## Installation 1. Copy `NANDR_ORB_OB_EA.mq5` to your MetaTrader 5 `MQL5/Experts/` folder 2. Open **MetaEditor** (F4 in MT5) and compile the file (F7) — should produce zero errors 3. In MT5, open a **XAUUSD M15** chart 4. Drag the EA onto the chart, enable **"Allow Algo Trading"** 5. In the inputs dialog, enable at least one session (e.g. `InpUseLondonSession = true`) 6. Click OK — the EA will auto-detect the broker's XAUUSD symbol variant --- ## Requirements - MetaTrader 5 (build 2755+) - XAUUSD (or broker equivalent: XAUUSD.s, XAUUSD_, GOLD, etc.) - Recommended chart timeframe: **M15** - Account type: any (ECN recommended for tighter spreads on Gold) --- ## Files | File | Description | |------|-------------| | `NANDR_ORB_OB_EA.mq5` | Expert Advisor source code | | `orb.pine` | Reference Pine Script — ORB indicator (TradingView) | | `order_block_detector.pine` | Reference Pine Script — LuxAlgo Order Block Detector | --- ## Disclaimer This EA is provided for educational purposes. Past performance does not guarantee future results. Always test thoroughly on a **demo account** before using on live funds. Trading Gold (XAUUSD) carries significant risk.