Unisciti alla nostra fan page
OvernightIndex EA - overnight long on US index CFDs, flat at the rollover - sistema esperto per MetaTrader 5
- Visualizzazioni:
- 10
- Pubblicato:
-
Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance
RESEARCH / EDUCATIONAL TOOL - NOT FINANCIAL ADVICE. CFDs are leveraged products and most retail accounts lose money. Past results do not guarantee future results. Test on a demo account first. The author accepts no responsibility for any loss.

What it does
OvernightIndex_EA holds long positions on US stock-index CFDs only during the overnight hours:
- it buys at 18:05 New York time, right after the daily 17:00-18:00 halt of the US index futures (00:05 on a Central-European server clock);
- it sells at 09:25 New York time, before the US cash session opens (15:25 server time);
- one trade per symbol per night, from Sunday night to Thursday night. No trades on Friday evening or on weekends.
Default symbols: UsaTec (Nasdaq 100), Usa500 (S&P 500) and UsaInd (Dow Jones). The total exposure is 100% of equity, split equally across the symbols. A 3 x daily ATR stop is only a safety net: it was never hit in the tests. A drawdown guard pauses new entries for 14 days after a 25% equity drawdown.
Why the swap is avoided (assumption to verify)
CFD swap is charged on positions that are open at the broker's daily rollover (17:00 New York = 23:00 on a Central-European server). The EA is always flat at that moment, so the -6.86% per year that the tested broker charges on index longs is not paid. In the Strategy Tester the swap of every trade was 0, while a control run that held the same positions through the rollover paid EUR -609 of swap in two years on UsaTec. Check the swap column on your own account: brokers differ. In the 4-5 weeks a year when the US and European clocks differ, the entry is at 23:05 server time.
What it is NOT
It is long equity-index exposure (market beta), not a market-neutral edge. It earns when the indices rise and loses when they fall (2022: about -7% on the basket). The same EA allowed to hold during the US cash session as well (sell at 16:45 New York instead) made +381% with a 33% drawdown on UsaTec over the same period, so restricting the exposure to the night did not improve the return per unit of risk in this sample; it only reduces the time in the market.
Backtest results (all data)
Conditions: ActivTrades demo history, EUR 10,000 account, leverage 1:100, 2018-01-02 to 2026-10-15, Strategy Tester "1 minute OHLC" model, broker spreads and swaps, no commissions, default settings, 100% exposure.
Default basket (UsaTec + Usa500 + UsaInd):
- Net profit +80.0% (final balance EUR 18,004, about +6.9% a year compounded), profit factor 1.16, maximum equity drawdown 12.9%, 6,341 trades, 55.6% winners, swap EUR 0, positive in 8 of 9 calendar years.
- Per calendar year (EUR, compounded, start 10,000): 2018 +144, 2019 +1,206, 2020 +3,828, 2021 +644, 2022 -987, 2023 +68, 2024 +1,209, 2025 +756, 2026 (to 15 Oct) +1,136.
- Per period, each starting from EUR 10,000: 2018-2020 +51.9% (PF 1.37, drawdown 8.3%); 2021-2022 -3.8% (PF 0.96, drawdown 11.9%); 2023-2024 +9.4% (PF 1.15, drawdown 5.0%); 2025-2026 +15.2% (PF 1.19, drawdown 8.7%).
Single symbols, 100% exposure each: Usa500 +96.6% (PF 1.18, drawdown 14.4%); UsaTec +112.3% (PF 1.15, drawdown 18.3%); UsaInd +71.2% (PF 1.14, drawdown 15.1%).
Exposure of the basket: 50% of equity +42.7% (drawdown 8.3%); 200% +231.9% (drawdown 30.9%). With the optional SMA(200) trend filter (InpTrendSMA = 200) +42.7% (PF 1.15, drawdown 8.3%, positive in 6 of 9 years).
Every-tick check (ticks generated from M1) on the basket for 2024 alone: +8.7%, PF 1.29, drawdown 4.4%, 717 trades, swap 0 - the same result as the 1 minute model. No real-tick test was run.
Important notes on these numbers
- Most of the profit comes from 2019-2020 (strong Nasdaq rally). 2021-2022 was flat to negative, and the effect has been weaker since 2020 than before.
- The idea was found and tested on the same broker data. It did NOT pass a strict out-of-sample validation: regard it as unproven. The months of 2025-2026 were looked at before this publication, so they are not a clean hold-out.
- Slippage and spreads at 00:05 server time can be worse in real trading than in the history. Each extra basis point of cost removes roughly one fifth of the average gain.
- Minimum lot: on small accounts the minimum lot of an index can be larger than the target exposure. The EA then skips that symbol for the day and writes it in the Experts log.
How to use
1. Copy OvernightIndex_EA.mq5 into MQL5\Experts (File - Open Data Folder), compile it in MetaEditor and attach it to ONE chart (any symbol and timeframe, for example UsaTec H1). Enable algo trading.
2. Set InpSymbols to the symbol names of your broker (for example US100,US500,US30). The symbols must be visible in Market Watch.
3. Server time: the default (InpServerMinusNY = 0) assumes a server on Central-European time (New York = server - 6 h, or - 5 h in the weeks when only the US has changed to summer time). If your server follows GMT+2/+3 with US daylight saving, set InpServerMinusNY = 7. Check: at 17:00 New York the server clock must show 23:00 (or 00:00 with the 7 h setting).
4. Netting accounts: a position of another EA on the same symbol would be merged with this one.
Two .set presets are attached: the default basket and Usa500 only.
Inputs
InpSymbols, InpEntryNYMin (1085 = 18:05 New York), InpExitNYMin (565 = 09:25 New York), InpServerMinusNY, InpNotionalPct (total exposure, % of equity), InpMinLotMaxOver, InpMaxSpreadPct, InpStopATRMult, InpTrendSMA, InpMaxDDPct, InpCooldownDays, InpMagic, InpDeviation.
Disclaimer: this code is provided for educational and research purposes only and is not investment advice. Trading CFDs involves a high risk of loss. Backtests are hypothetical, based on historical data and do not guarantee future performance. Use at your own risk.
Non-Repainting Fair Value Gap Detector
Non-repainting three-bar Fair Value Gap detector for MetaTrader 5. Closed-bar detection, the 50% Consequent Encroachment level, mitigation as an explicit state machine, incremental scanning, and a built-in self-audit that re-checks the stored gap levels against the closed-bar series on attach. Pure native MQL5, no DLLs, no external dependencies.
Contract Sizer: ladder, floor and a breaker that survives a deposit
Tre meccanismi di protezione per il dimensionamento delle posizioni che funzionano in modo diverso; confonderli è il motivo per cui così tanti conti vengono azzerati: - ladder: un contratto ogni X del saldo, applicato sempre come limite massimo (CAP), anche con il dimensionamento manuale dei lotti; - floor: al di sotto del capitale minimo non effettua operazioni; è necessario un nuovo versamento; - breaker: si attiva all’X% al di sotto del picco, indipendentemente dalle dimensioni del conto, e non si riattiva automaticamente. Ciò che questa libreria risolve e che quasi nessuna altra fa: un versamento non è un profitto, e un prelievo non è una perdita. Il «breaker» misura il calo rispetto al picco del saldo. Se non gestita, un'operazione di deposito effettuata DURANTE un drawdown fa aumentare contemporaneamente sia il saldo che il picco, e la protezione smette di rilevare il calo proprio nel momento in cui sarebbe utile. In questo caso, depositi e prelievi spostano il picco dello stesso importo. Il picco viene salvato in un file: un «breaker» che dimentica il picco al riavvio del terminale non è un «breaker». La demo simula un deposito al punto più basso di un calo. Eseguila con il deposito attivato e disattivato e confronta la colonna «calo».
GM Matrix Monitor — read-only risk dashboard for your EA matrix
Read-only panel showing per-magic net P/L, account drawdown, daily-loss breaker progress and freeze/liquidate thresholds. Does NOT trade.
Trend Buy/Sell Zones with Auto Lot Size - Risk Panel
Highlights potential buy zones in uptrends and sell zones in downtrends on closed candles (no repainting), with automatic lot size for your balance and a daily loss guard.