# 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** (candle closing beyond the range; optional strict N-bar filter to avoid false breaks) 3. Wait for price to **retest** the broken ORB level 4. Enter on the retest, sized and stopped by the selected **ORB Risk Method** ### ORB Risk Methods (coupled SL + Reward:Risk) The `InpOrbRiskMethod` input selects a risk profile that fixes **both** the stop-loss placement and the reward:risk target together, per the ORB strategy specification: | Method | Stop Loss | Reward:Risk | |--------|-----------|-------------| | `Boundary 1:2` (default) | Broken range boundary (long=ORH, short=ORL) | 1:2 | | `Mid 1:1.5` | Range midpoint (50%) | 1:1.5 | | `Opposite 1:1` | Opposite range boundary (long=ORL, short=ORH) | 1:1 | | `Legacy` | Uses `InpSLMode` / `InpTPMode` / `InpRRRatio` manually | — | If the chosen method produces an invalid stop (wrong side of entry), the EA falls back to the legacy `InpSLMode` / `InpTPMode` settings. ### Daily Bias The `InpDailyBiasMode` input controls which trade directions are permitted each day: | Mode | Behaviour | |------|-----------| | `Auto` (default) | The first confirmed ORB breakout of the day sets the tradeable direction; later trades must align with it | | `Off` | No trades taken today (use on news / high-uncertainty days) | | `Long only` | Only long entries processed | | `Short only` | Only short entries processed | Breakout **detection** is never suppressed — only trade **execution** is gated, so levels and structure keep updating regardless of bias. ### 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 add-on, **disabled by default** via `InpUseOBRetestEntry`). Active exposure is session-scoped: one open trade is allowed per session, and different sessions may each hold one trade on the same day. ### Session Level Ladder (optional, disabled by default) - After a confirmed session breakout direction, the EA can trade between that session's ORB levels: - Bullish ladder: `Low -> Mid`, then `Mid -> High` - Bearish ladder: `High -> Mid`, then `Mid -> Low` - Confirmation for ladder entries uses wick retest plus bar-close context. - Priority is ORB retest first, with ladder as fallback. - Ladder TP is always the next session level. SL is user-selectable (fixed pips or source-level buffer). --- ## 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 | 22:00 | Asian range setup | | Tokyo | 00:00 | Low volume, range-bound | | London | 08:00 | High volatility ✓ (8AM GMT) | | NY | 12:00 | High volatility ✓ | | NY ORB (Stock open) | 13:30 | Strong momentum ✓ (9:30 EDT) | All session start times are **UTC-based** and individually configurable via the `InpHour` / `InpMin` inputs. The EA converts them to broker server time internally. --- ## 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) | | `InpDailyOpenHour` / `InpDailyOpenMin` | `22` / `0` | Daily Open start (UTC) | | `InpTokyoHour` / `InpTokyoMin` | `0` / `0` | Tokyo start (UTC) | | `InpLondonHour` / `InpLondonMin` | `8` / `0` | London start (UTC = 8AM GMT) | | `InpNYHour` / `InpNYMin` | `12` / `0` | NY start (UTC) | | `InpNYOrbHour` / `InpNYOrbMin` | `13` / `30` | NY ORB start (UTC = 9:30 EDT) | ### 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` | `false` | Strict N-bar breakout filter (`false` = simple close-cross) | | `InpWaitForRetest` | `true` | Wait for an ORB retest before entering | | `InpBreakoutExpireBars` | `20` | Bars before an armed breakout expires (`0` = never) | | `InpUseOBRetestEntry` | `false` | Order Block retest entry add-on (optional, default OFF) | | `InpMaxRetestsPerSession` | `3` | Max retest entries per session (per breakout) | | `InpDailyBiasMode` | `Auto` | Daily bias: Auto / Off (no trades) / Long-only / Short-only | | `InpUseBreakoutVolFilter` | `false` | Require a volume spike on the breakout bar (fakeout filter) | | `InpBreakoutVolMult` | `1.5` | Breakout bar volume must be ≥ this × average volume | | `InpBreakoutVolAvgBars` | `20` | Number of bars used for the volume average | ### Session Level Ladder Settings | Parameter | Default | Description | |-----------|---------|-------------| | `InpUseSessionLevelLadder` | `false` | Enable level-to-level ladder entries after breakout direction confirmation (optional, default OFF) | | `InpLadderOnDailyOpen` | `true` | Enable ladder entries on Daily Open session | | `InpLadderOnTokyo` | `true` | Enable ladder entries on Tokyo session | | `InpLadderOnLondon` | `true` | Enable ladder entries on London session | | `InpLadderOnNY` | `true` | Enable ladder entries on NY session | | `InpLadderOnNYORB` | `true` | Enable ladder entries on NY ORB session | | `InpUseLadderATRVolCeiling` | `false` | Enable ATR volatility ceiling filter for ladder entries | | `InpLadderATRMaxPips` | `200.0` | Skip ladder entries when ATR exceeds this pips threshold | | `InpUseLadderSessionCaps` | `false` | Enable per-session ladder trade caps | | `InpLadderCapDailyOpen` | `2` | Daily Open ladder cap (`0` = unlimited) | | `InpLadderCapTokyo` | `2` | Tokyo ladder cap (`0` = unlimited) | | `InpLadderCapLondon` | `2` | London ladder cap (`0` = unlimited) | | `InpLadderCapNY` | `2` | NY ladder cap (`0` = unlimited) | | `InpLadderCapNYORB` | `2` | NY ORB ladder cap (`0` = unlimited) | | `InpLadderSLMode` | `Fixed Pips` | Ladder SL mode: fixed pips or buffer beyond source level | | `InpLadderSLBufferPips` | `5.0` | Buffer size when ladder SL mode is level-buffer | | `InpLadderMaxTradesPerSession` | `2` | Global ladder cap per session (`0` = unlimited); combined with per-session cap using the stricter limit | ### Lot Size & Risk | Parameter | Default | Description | |-----------|---------|-------------| | `InpLotMode` | `Risk %` | Fixed lot or auto-calculated from risk % | | `InpFixedLotSize` | `0.05` | Fixed lot (used when LotMode = Fixed) | | `InpRiskPercent` | `0.05` | % of balance to risk per trade | ### Stop Loss | Parameter | Default | Description | |-----------|---------|-------------| | `InpOrbRiskMethod` | `Boundary 1:2` | Coupled risk method (sets SL + RR together); `Legacy` uses the manual settings below | | `InpSLMode` | `OB Boundary` | SL placement (Legacy only): OB Boundary / Fixed Pips / ATR-based / ORB Opposite Boundary / ORB Range Midpoint | | `InpSLPips` | `100.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 (Legacy only) | | `InpTPPips` | `100.0` | TP in pips (Fixed mode) | | `InpRRRatio` | `2.0` | Risk:Reward ratio (Legacy 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` | `8` | 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.