# GoldSeasonality.mq5

Original MIT-licensed Expert Advisor. Source idea: [Quantpedia, 6 August 2018](https://quantpedia.com/an-extensive-test-of-market-timing-strategies-in-the-gold-market/). The source holds gold in September and November. These experiments test its two components separately: `SEPTEMBER=9` and `NOVEMBER=11`. Run each with a separate tester run and a distinct magic number. Do not run both on the same netting symbol/account.

## Exact execution rules

- Use an EUR account and the broker's USD-quoted gold symbol plus direct EURUSD conversion symbol. Inputs accept suffixes; attach to the selected gold symbol's chart.
- Observe a UTC month boundary, then buy on the first available gold tick in the selected month. Hold one long position and close on the first available tick in the next month. Trading downtime, stale conversion quotes, rejected orders, and retries can delay fills.
- Start before the selected month. Initialization/restart during that month manages an existing matching position but does not create a late entry. Restart after an unfilled boundary loses that month's entry opportunity. No re-entry after a filled position closes within that month.
- Size at 100% account equity notional, using `equity_EUR * EURUSD_ask / gold_ask / contract_size`, rounded down to the broker's lot step. Read actual broker contract/min/max/step and verify available margin. Never round up to a minimum lot. No other account exposures should be present when comparing the Python test.
- No stop or profit target. This is an unlevered-notional allocation rule, not a fixed-risk-per-trade strategy. Losses can gap; the EA does not implement FTMO guard rails or certify a challenge pass.
- `InpDeviationPoints` is a broker execution tolerance in symbol points. It is not a guaranteed slippage charge and differs from an explicit Python slippage model. Execution at market may reject or fill beyond a tolerance depending on the broker's execution mode.

## UTC and historical tester setup

Live mode uses `TimeGMT()` and therefore relies on the terminal computer's correct clock and timezone. MetaQuotes documents that in Strategy Tester `TimeGMT()` equals simulated server time. The EA therefore uses `TimeCurrent() - InpTesterServerUTCOffsetMinutes*60` in tests. Use **0** for imported UTC Dukascopy custom-symbol data.

A fixed offset is insufficient for broker history with changing summer/winter server offsets. Normalize the historical data to UTC and use a custom symbol, or implement and audit that broker's historical timezone schedule before comparing fills. Do not silently use broker midnight as UTC.

Test January 1, 2016 through January 1, 2026 inclusive of enough ending ticks to settle the final requested holding. Start EUR 10,000, use each month separately, and use tick data where available. Configure XAU contract size 100 oz and minimum/step 0.01 lot if matching the Python model. Check the broker/custom-symbol specification, conversion series, spread, commissions, swap and session calendar.

## Costs and differences from Python

The EA uses real broker spreads, commissions, conversion, swap and financing. It does **not** artificially deduct an assumed annual funding rate. The Python research model's 5% annual financing assumption is a disclosed scenario, not a broker swap history. Exact P&L parity requires equivalent broker symbols, costs, conversion quotes, tick ordering, sizing and calendar boundaries. A daily-candle Python test and this tick-driven EA are separate execution models.

## Order and account handling

Synchronous CTrade requests are logged with retcodes, deals and orders. Successful structure validation is not treated as proof of execution. Failed or partial exits retry on later ticks with a five-second default cooldown. A partial entry fill is accepted without top-up. Any active symbol order blocks a new entry. Existing positions with other magic numbers are never closed. Netting positions containing foreign/manual deals are also protected; use a dedicated account/symbol and unique magic because independent systems cannot safely share one netting position. The EA cancels its own still-active orders outside the holding month and waits for settlement before submitting another close. An accepted market request that cannot be cancelled may fill late; its resulting position is closed on a subsequent tick. It never cancels foreign orders. It submits no pending orders.

## Verification status

Source reviewed only. MetaEditor and MT5 are unavailable in this environment, so this file has **not been compiled or backtested in MT5**. Compile with F7 in MetaEditor, inspect all diagnostics, then run the two tester cases and inspect boundary fills, lot sizing, rejected requests, partial fills and funding. The Python historical results, when available, are not MT5 results.

Official references checked:

- [TimeGMT and the Strategy Tester exception](https://www.mql5.com/en/docs/dateandtime/timegmt)
- [CTrade Buy and trade-result checks](https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade/ctradebuy)
- [PositionClose and ticket-specific hedging behavior](https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade/ctradepositionclose)
