# OPEXWeek.mq5

Original Edge Quant implementation, MIT license. **One EURUSD long-only U.S. equity-calendar transfer**, with an EUR 10,000 research account. This is **not a claim about EURUSD option expirations or an established FX expiry premium**. The complete package requires **OPEXWeek.mq5 plus sessions.csv**, using only MetaTrader's standard `Trade/Trade.mqh` and built-in file/hash functions.

Sources read directly: [Quantified Strategies, June 21, 2024](https://quantifiedstrategies.substack.com/p/the-options-expiration-week-effect-2a7) explicitly buys the equity expiration week's open and sells the expiration day's close, shifting around Monday/Friday holidays. Its [March 20, 2026 companion](https://quantifiedstrategies.substack.com/p/the-options-expiration-week-effect-aa2) states the third Friday. Source equity results do not transfer to this FX test. All twelve months are retained; no January/July or other month exclusion is added.

## Frozen calendar rule

1. Find the **literal third Friday**, always day **15–21** of each month. Identify its Monday–Friday calendar week.
2. Select the **first actual XNYS session** in that week for entry and the **last actual XNYS session** in that week for exit. A Monday holiday can move entry to Tuesday; a Friday holiday can move exit to Thursday. Calendar rows, not weekday guesses, determine the actual boundaries.
3. Enter long only at the first session's **exact scheduled 09:30 New York M5 opening interval**. A missing opening quote, unready context, conversion age over 900 seconds or failed sizing/submission consumes that month. Do not enter at a later quote or wait for fresh conversion.
4. Exit on the first available tick at/after the final session's **actual calendar close**. Persist a rejected/delayed exit across gaps. Exit before considering a new monthly entry.
5. One position, all months, no SL/TP, technical filter or other historical signal rule. This is not a fixed number of elapsed holding hours or trading sessions.

The companion's parenthetical “Friday before the third Saturday” is not always equivalent to its explicit third-Friday rule. For example, November 2025 began Saturday: the literal third Friday was **November 21**, whereas the Friday before the third Saturday was November 14. This study freezes the literal day-15–21 definition, before outcomes.

## Required CSV and installation

Put `OPEXWeek.mq5` under **MQL5/Experts/** and copy the supplied **sessions.csv unchanged into MQL5/Files/**. The main source declares `#property tester_file "sessions.csv"` so MT5 transfers this dependency to its testing agent. The `.mq5` by itself is not the complete package.

The supplied XNYS calendar contains **4,021 sessions across 2015–2030**. Its SHA-256 is:

```
3cbbac4e5d20f5f2471fb476521a6106b6a6b3959e808dc380d86e3c4f10558d
```

Initialization verifies raw bytes, schema and session ordering, then constructs **192 monthly events**. The calendar supplies New York DST, holidays and actual early closes. Missing/modified CSV fails initialization; text-editor newline changes also alter the hash. Preserve the download bytes. The package includes the calendar generator, manifest and pinned requirements. Future unannounced closures need a reviewed calendar/hash update, not guessed dates. New entries stop beyond calendar coverage; existing owned positions retain exit management.

Initialization checks include Monday-holiday January 2017 entry on Tuesday 17; Good Friday April 2025 exit on Thursday 17; Juneteenth June 2026 exit on Thursday 18; and November 2025's literal-Friday distinction. Dates come from the exact CSV used by Python.

## Fills, initialization and restart

The historical model uses the exact scheduled opening M5 quote plus costs. Live terminal/network/broker latency can change actual fills; the quote-response approximation is not a guaranteed live opening fill.

Operational safeguards are separate from the historical rule: latch the first observed M5 interval and consume its monthly event before requesting quote history or FX; require a timestamp matching the scheduled opening; reject live attachment after that interval began. Exact-boundary-second initialization is allowed. Later loaded context or fresh FX cannot revive a skipped month. These safeguards can reduce actual entries; they are not optimized calendar filters.

The tester starts flat in 2016 without carrying a prior position. No price-indicator warmup is needed. Offline/missed opening events are consumed without backfilling historical entries. A terminal marker keyed to account/server/symbol/magic and matching own broker comments prevent duplicate monthly submissions; tester/live state is separate.

Position comments `OPX:<entry_open_utc>:<calendar_exit_utc>` preserve the already known exit schedule. Restarts validate both epochs against the monthly event table. The deadline does not move with fill time or restart. Invalid/missing comments, wrong direction or multiple exclusively owned positions trigger operational flattening rather than invented state. Late accepted fills after the deadline are exited; visible expired entry remainders are cancelled.

## EUR budget and broker differences

Use an **EUR-denominated account**, attach to the selected direct EURUSD symbol, and select the direct EURUSD conversion symbol, including broker suffixes. Set tester deposit to **EUR 10,000**. Actual broker contract/minimum/maximum/step/directional limit and free margin are read at runtime. Research assumes **100,000 EUR/lot** and **0.01-lot minimum/step**:

```
raw_lots = equity_EUR /
    (contract_EUR * (trade_ask + 0.00001) / conversion_ask
     + 3.50 / conversion_bid)
```

Floor to the lot step and never round up to a minimum. This targets approximately **1× current EUR equity notional**, reserving 0.1-pip adverse entry slippage and USD 3.50/lot commission. Conversion must be no more than **900 seconds old**, without using future-dated quotes; otherwise skip the month. Exits have no conversion-freshness filter. Use a dedicated account because unrelated exposure changes equity/margin.

Python models supplied bid/ask, 0.1-pip adverse slippage per side, USD 3.50/lot/side commission and **5% assumed annual financing** for elapsed time. The EA uses actual broker fills, fees, conversion and swap, without artificial funding or slippage charges. `InpDeviationPoints` is an execution tolerance, not guaranteed slippage. Quote ordering/granularity, contract metadata and costs can change results.

## UTC handling, ownership and verification

`InpServerUTCOffsetMinutes` is a **fixed** offset for historical M5/order timestamps. Tester UTC is `TimeCurrent() - offset*60`; use **0** for imported UTC data. Live UTC uses the computer's `TimeGMT()`. [MetaQuotes documents that tester TimeGMT equals simulated server time](https://www.mql5.com/en/docs/dateandtime/timegmt). The CSV handles New York DST, but the fixed quote-history offset cannot infer a broker's historical DST schedule. Normalize quotes to UTC or separately audit that schedule. Bid-based chart mode is required.

Only matching-magic owned tickets are closed. Netting ownership additionally requires available nonempty position history containing exclusively matching-magic trades. Foreign/mixed exposure and orders are untouched and block entry. Temporary ownership-history failure is not verified flat. Required exit management runs before entry-checkpoint recovery, so entry-history failure does not suspend an otherwise safe owned exit.

Retcodes/order/deal IDs are checked and logged. Active/unresolved accepted requests block duplicates; partial entries are accepted without top-up. Required exits retry and cancel own entry remainders. Known unresolved order history stays latched; missing exit IDs permit logged, cooldown-limited ticket-specific recovery. Ambiguous entries are not blindly repeated. Keep magic and saved state intact; broker/network failures may still require investigation.

**MetaEditor/MT5 are unavailable: OPEXWeek.mq5 has not been compiled or backtested in MT5.** Independent static review found no material defect or obvious API blocker. All **192 monthly events** and holiday anchors were independently reconstructed from the hashed calendar; all **120 evaluation-month schedule audits** matched, including nine shifted Monday entries and three shifted Friday exits. These are calendar checks, not MT5 trade results.

Compile with F7 and inspect diagnostics. Test the one case on 2016–2025 UTC quotes with the bundled calendar and matching broker settings. Verify literal Fridays, holiday shifts, exact opening availability, stale FX, delayed closing fills and restart recovery. M5 OHLC cannot certify full tick execution or intrabar FTMO compliance. Python results are not MT5 results or FTMO certification.
