Unisciti alla nostra fan page
- Visualizzazioni:
- 27
- Valutazioni:
- Pubblicato:
- 2025.04.03 11:16
-
Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance
MetaTrader5 dispone di una cronologia volumetrica aggiornata degli eventi fondamentali del calendario, i cui dati possono essere consultati in modo programmatico.
Questa libreria consente di lavorare comodamente con questi dati. In particolare, di utilizzarli nel Tester e nel trading reale.
Il funzionamento della libreria è illustrato sotto forma di commenti al codice sorgente degli esempi.
Ottenere i dati storici.
// Lo script produce dati storici. #include <fxsaber\Calendar\Calendar.mqh> // Calendario - analisi fondamentale sulla storia e in tempo reale. void OnStart() { CALENDAR Calendar; // Ha preso gli eventi per tutte le valute (NULL) a partire da quella di minore importanza (NONE). const int Size = Calendar.Set(NULL, CALENDAR_IMPORTANCE_NONE, D'2020.12.07', D'2020.12.08'); // Stampateli. for (int i = 0; i < Size; i++) Print(Calendar[i].ToString()); }
Risultato.
2020.12.07 AllDay EUR 0 День Конституции(constitution-day), Испания(ES) | | | | 2020.12.07 00:00 AUD 3 Выступление председателя Резервного Банка Австралии Лоу(rba-governor-lowe-speech), Австралия(AU) | | | | 2020.12.07 01:50 JPY 1 Международные резервы(jp-foreign-reserves), Япония(JP) | $1384.6 B | | $1384.4 B | 2020.12.07 02:30 AUD 1 Количество объявлений о вакансиях от ANZ м/м(anz-job-advertisements-mm), Австралия(AU) | 13.9% | 0.8% | 9.4% | 2020.12.07 ≈05:00 CNY 1 Объем импорта USD г/г(imports-usd-yy), Китай(CN) | 4.5% | 4.4% | 4.7% | 2020.12.07 ≈05:00 CNY 1 Объем экспорта USD г/г(exports-usd-yy), Китай(CN) | 21.1% | 3.6% | 11.4% | 2020.12.07 ≈05:00 CNY 2 Торговый баланс(trade-balance), Китай(CN) | ¥507.1 B | ¥271.31 B | ¥401.75 B | 2020.12.07 ≈05:00 CNY 2 Торговый баланс USD(trade-balance-usd), Китай(CN) | $75.42 B | $52.55 B | $58.44 B | 2020.12.07 ≈05:00 CNY 1 Объем импорта г/г(imports-yy), Китай(CN) | -0.8% | -0.6% | 0.9% | 2020.12.07 ≈05:00 CNY 1 Объем экспорта г/г(exports-yy), Китай(CN) | 14.9% | 2.2% | 7.6% | 2020.12.07 07:00 JPY 1 Индекс совпадающих индикаторов(coincident-index), Япония(JP) | 89.7 | 81.8 | 81.1 | 84.8 2020.12.07 07:00 JPY 1 Индекс ведущих экономических индикаторов(leading-index), Япония(JP) | 93.8 | 92.7 | 92.5 | 93.3 2020.12.07 07:00 JPY 1 Индекс совпадающих индикаторов Японии м/м(coincident-index-mm), Япония(JP) | 4.9% | | 1.7% | 2.4% 2020.12.07 07:00 JPY 1 Индекс ведущих экономических индикаторов м/м(leading-index-mm), Япония(JP) | 0.5% | | 4.0% | 4.2% 2020.12.07 08:00 ZAR 1 Валовые международные резервы(gross-international-reserves), Южно-Африканская Республика(ZA) | $53.76 B | $54.129 B | $53.658 B | 2020.12.07 08:00 ZAR 1 Чистые международные резервы(net-international-reserves), Южно-Африканская Республика(ZA) | $51.257 B | $52.719 B | $51.364 B | 2020.12.07 09:00 EUR 2 Промышленное производство г/г(industrial-production-yy), Германия(DE) | -3.0% | -11.4% | -7.3% | -6.7% 2020.12.07 09:00 EUR 2 Промышленное производство м/м(industrial-production-mm), Германия(DE) | 3.2% | 7.7% | 1.6% | 2.3% 2020.12.07 09:00 NOK 1 Производство в обрабатывающей промышленности м/м(manufacturing-production-mm), Норвегия(NO) | 0.6% | 0.1% | -0.5% | 2020.12.07 09:00 NOK 1 Производство в обрабатывающей промышленности г/г(manufacturing-production-yy), Норвегия(NO) | -2.7% | -3.3% | -3.4% | 2020.12.07 09:00 NOK 1 Промышленное производство м/м(industrial-production-mm), Норвегия(NO) | -3.5% | 0.0% | -1.7% | -1.6% 2020.12.07 09:00 NOK 1 Промышленное производство г/г(industrial-production-yy), Норвегия(NO) | 0.0% | 6.9% | 6.3% |
È possibile confrontarlo con il terminale MT5 stesso.
Ottenere i prossimi eventi.
// Lo script visualizza i prossimi eventi. #include <fxsaber\Calendar\Calendar.mqh> // Calendario - analisi fondamentale sulla storia e in tempo reale. void OnStart() { CALENDAR Calendar; string Currencies[2]; // Ottenere le valute del carattere corrente. Currencies[0] = ::SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE); Currencies[1] = ::SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT); // Ha selezionato i prossimi eventi importanti in base alle valute simbolo. Calendar.Set(Currencies); Print(Calendar.ToString()); // Stampateli. }
Questo tipo di integrazione nei sistemi informativi consente di informare sugli eventi importanti del calendario in arrivo negli Expert Advisor/indicatori.
Backtest su dati fondamentali.
Qui di seguito è riportato un Expert Advisor che opera sui NonFarm Payrolls confrontando i valori attuali con quelli previsti.
// Expert Advisor per il trading in MT4/5-Tester sulla storia dei dati fondamentali. #define CALENDAR_FILENAME "Calendar.bin" // Nome del file per la lettura/scrittura del Calendario. #property tester_file CALENDAR_FILENAME // Specifica che MT5-Tester preleva questo file. #include <fxsaber\Calendar\Calendar.mqh> // Calendario - analisi fondamentale sulla storia e in tempo reale. input group "Calendar" input string inCurrency = "USD"; // Valuta input string inFilterName = "payrolls"; // NomeFiltro input group "EA" input int inTP = 1000; // TakeProfit input int inSL = 1000; // StopLoss input bool inReverse = true; // Direzione del commercio CALENDAR Calendar; // Oggetto con i dati del calendario. int OnInit() { bool Res = false; if (MQLInfoInteger(MQL_TESTER)) // Se si lavora in Tester { Res = Calendar.Load(CALENDAR_FILENAME) && // Carica gli eventi dal file. Calendar.FilterByCurrency(inCurrency) && // Applicazione di un filtro per la valuta. Calendar.FilterByName(inFilterName); // Applica un filtro sul nome dell'evento. if (!Res) // Se ci sono problemi con i dati caricati, Print("Run the EA in the MT5-Terminal!"); // ha riferito che è necessario ottenerli eseguendo l'EA in MT5-Terminal. } #ifdef __MQL5__ // Lavorare nel terminale. else if (Calendar.Set(NULL, CALENDAR_IMPORTANCE_NONE, 0, 0) && // Caricati assolutamente tutti gli eventi (storia + futuro) dal terminale MT5. Calendar.Save(CALENDAR_FILENAME)) // Salvarli in un file. MessageBox("You can run the EA in the MT4/5-Tester."); // Segnalato che ora possiamo lavorare in MT4/5-Tester. #endif // #ifdef __MQL5__ return(!Res); } void OnTick() { static int Pos = Calendar.GetPosAfter(TimeCurrent()); // Ottenere la posizione dell'evento nel calendario, che è subito dopo l'ora corrente. if ((Pos < Calendar.GetAmount()) && // Se non siete andati oltre il Calendario (Calendar[Pos].time < TimeCurrent())) // e l'ora corrente ha superato l'evento. { const EVENT Event = Calendar[Pos]; // Ricevuto l'evento corrispondente. if ((Event.Actual != LONG_MIN) && (Event.Forecast != LONG_MIN)) // Se i valori attuali e previsti dell'evento sono impostati { Print(Event.ToString()); // Stampa questo evento nella sua interezza. if (Event.Actual > Event.Forecast) // Se il valore attuale è maggiore del valore previsto, PositionOpen(inReverse, "Act.(" + Event.ActualToString() + ")>(" + Event.ForecastToString() + ")For."); // aprire una posizione di una direzione. else PositionOpen(!inReverse, "Act.(" + Event.ActualToString() + ")<=(" + Event.ForecastToString() + ")For."); // Altrimenti, un'altra direzione. } Pos = Calendar.GetPosAfter(TimeCurrent(), Pos); // Ottenere la posizione dell'evento nel calendario, che è subito dopo l'ora corrente. } } #include <MT4Orders.mqh> // https://www.mql5.com/it/code/16006 #define Bid SymbolInfoDouble(_Symbol, SYMBOL_BID) #define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK) // Apre una posizione con il commento specificato. TICKET_TYPE PositionOpen( const int Type, const string comment ) { return(Type ? OrderSend(_Symbol, OP_SELL, 1, Bid, 0, Bid + inSL * _Point, Bid - inTP * _Point, comment) : OrderSend(_Symbol, OP_BUY, 1, Ask, 0, Ask - inSL * _Point, Ask + inTP * _Point, comment)); }
Eseguirlo una volta in MT5-Terminal per salvare tutti i dati storici (~60 Mb). Successivamente saranno disponibili nel Tester.
Risultato (per sei anni ai prezzi di apertura H1).
Caratteristiche.
- Non utilizza DLL, può essere eseguito nel Marketplace.
- Funzionamento multipiattaforma: in MT4 ottiene i dati dal file.
Tradotto dal russo da MetaQuotes Ltd.
Codice originale https://www.mql5.com/ru/code/32430

Dati del tester a passaggio singolo.

A zigzag based on the trend change of the parabolic sar

Rilevare l'inizio di una nuova barra o candela nel gestore dell'evento OnTick() di un Expert Advisor.

This Bot detects the open of a new candle on any set timeframe, thereby making it easier to run a one-time code, place trades and call other functions. The code is written in the OnTick() function.