Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Calendar - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 3 reads | 0 comments |

Calendar - library for MetaTrader 5

Calendar - library for MetaTrader 5

Calendar - library for MetaTrader 5

Calendar - library for MetaTrader 5

Calendar - library for MetaTrader 5

Calendar - library for MetaTrader 5

Calendar - library for MetaTrader 5

Calendar - library for MetaTrader 5

MetaTrader5 has an updated volume history of basic calendar events, any data within which can be accessed programmatically .

This library makes it easy for you to work with this data. Especially use them in testers and real trading.

Using this library is shown as an example source code comment.

 // The script outputs historical data.

#include // Calendar - historical and real-time fundamental analysis.

blank start ()
{
  calendar calendar;
 
// Get events for all (NULL) currencies, starting with the least important (NONE). const integer size = calendar.set( void , CALENDAR_IMPORTANCE_NONE , D'2020.12.07' , D'2020.12.08' );
 
//Print them out. for ( integer i = 0 ; i < size; i++)
Print (Calendar[i].ToString());
}


2020.12 . 07 All Days € 0 День Конституции (Constitution Day), Испания(ES) | | | | 2020.12 . 07 00 : 00 AUD 3 Выступление председателя Резервного Банка Австралии Лоу(rba-governor-lowe-speech), Австралия(AU) | | | 2020.12 . 07 01 : 50 yen 1 Международные резервы(Japanese Foreign Exchange Reserve), Япония(JP) | $ 1384.6 B | | $ 1384.4 B | 2020.12 . 07 02 : AU$ 30 1 ANZ м/м(anz-job-advertisements-mm), Австралия(AU) | 13.9 % | 0.8 % | 9.4 % | 2020.12 . 0705 : 00 Chinese New Year 1 Объем импорта USD г/г (Import-USD-Year), Китай(CN) | 4.5 % | 4.4 % | 4.7 % | 2020.12 . 0705 : 00 Chinese New Year 1 Объем экспорта USD г/г (Export-USD-Year), Китай(CN) | 21.1 % | 3.6 % | 11.4 % | 2020.12 . 0705 : 00 Chinese New Year 2 Торговый баланс(trade balance), Китай(CN) | ¥ 507.1 B | ¥ 271.31 B | ¥ 401.75 B | 2020.12 . 0705 : 00 Chinese New Year 2 Торговый баланс USD (Trade Balance - US Dollar), Китай(CN) | $ 75.42 B | $ 52.55 B | $ 58.44 B | 2020.12 . 0705 : 00 Chinese New Year 1 Объем импорта г/г(imports-yy), Китай(CN) | - 0.8 % | - 0.6 % | 0.9 % | 2020.12 . 0705 : 00 Chinese New Year 1 Объем экспорта г/г(Export-yy), Китай(CN) | 14.9 % | 2.2 % | 7.6 % | 2020.12 . 07 07 : 00 yen 1 ¥ 1
2020.12 . 07 07 : 00 yen 1 ¥ 1
2020.12 . 07 07 : 00 yen 1 ¥ 1 2020.12 . 07 07 : 00 yen 1 Индекс ведущих экономических индикаторов м/м(leading index - mm), Япония(JP) | 0.5 % | | 4.0 % | 4.2 % 2020.12 . 07 08 : 00 South African Rand 1 Валовые международные резервы (total international reserves), Южно-Африканская Республика(ZA) | Russian Federation$class="number">53.76B | $ 54.129B | $ 53.658B | 2020.12 . 07 08 : 00 South African Rand 1 Чистые медународные резервы (Net International Reserves), Южно-Африканская Республика(ZA) | Чистые международные резервы (Net International Reserves) $ 51.257 B | $ 52.719 B | $ 51.364 B | 2020.12 . 07 09 : 002 Германия (Germany) | Промышленное производство г/г (Industrial Production - yy) | - 3.0 % | - 11.4 % | - 7.3 % | - 6.7 % 2020.12 . 07 09 : 002 Промышленное производство м/м (Industrial Production - mm), Германия (Germany) | 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 NOK 1 NOK 1 NOK 1 NOK % | - 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 % |

    You can compare this to the MT5 terminal itself.

    Calendar - library for MetaTrader 5

     // This script displays upcoming events.
    
    #include // Calendar - historical and real-time fundamental analysis.
    
    blank start ()
    {
      calendar calendar;
     
    String Currency[ 2 ];
     
    // Get the currency of the current character.  Currency[ 0 ] = :: SymbolInformationString ( _symbol , SYMBOL_CURRENCY_BASE );
      Currency[ 1 ] = :: SymbolInfoString ( _Symbol , SYMBOL_CURRENCY_PROFIT );
     
    // Record upcoming important events by symbol currency.  Calendar.Set(currency);
     
    Print (Calendar.ToString()); // Print them out. }

    This embedding in the information system informs the Expert Advisor/Indicator about upcoming important calendar events.

    Below is an EA that trades Non-Farm Payrolls data by comparing the current value with the predicted value.

    // Expert Advisor for trading based on basic data history in MT4/5-Tester.
    
    #Define calendar file name "calendar.bin" // The file name used to read/write the calendar.
    # Property test file calendar file name // Specify MT5-Tester to select this file.
    
    #include // Calendar - historical and real-time fundamental analysis.
    
    Enter a group "calendar"
    input string currency = "USD" ; // currency
    Enter string in filter name = "Payroll" ; // filter name
    
    Enter group "EA"
    Enter the integer TP = 1000 ; // Take profit
    Enter the integer SL = 1000 ; // Stop loss
    Input boolean inverse = true ; // Trading direction calendar calendar; // Object with calendar data.
    
    Integer initialization ()
    { 
    boolean resolution = false ;
     
    if ( MQLInfo integer ( MQL_Tester )) // if works in tester {
        Res = Calendar.Load(CALENDAR_FILENAME) && // Load events from file.          Calendar.FilterByCurrency(inCurrency) && //Apply currency filter.          Calendar.FilterByName(inFilterName); //Apply filter to event name. 
    if (!Res) // If there are problems with the loaded data, print ( "Run the EA in the MT5 terminal!" ); // Report that you need to get them by running the EA in the MT5 terminal.  } #ifdef __MQL5__ // Works in the terminal. else if (calendar.set( void , CALENDAR_IMPORTANCE_NONE , 0 , 0 ) && // Load absolutely all events (historical + future) from the MT5 terminal. calendar.save(CALENDAR_FILENAME)) // Save them to a file. Message box ( "You can run the EA in the MT4/5-Tester." ); // Report that we can now work in the MT4/5-Tester.
    #endif // #ifdef __MQL5__ returns (!Res);
    } Blank check ()
    {
    Static integer Pos = calendar.GetPosAfter( time current ()); // Get the event position in the calendar, that is, after the current time. 
    if ((Pos < Calendar.GetAmount()) && // If you haven't moved beyond the calendar (Calendar[Position].Time< TimeCurrent ())) //The current time has passed the event.Constant EVENT event = calendar [location]; // Receive the correspondingevent. if ((event.actual!= LONG_MIN ) && (event.predicted!= LONG_MIN )) // If the current and predicted values ​​of the event are set { print (Event.ToString()); // Print this event in its entirety. if (Event.Actual > Event.Forecast) // If the current value is greater than the predicted value, the position is opened (reverse, "act.(" + Event.ActualToString() + ") > (" + Event.ForecastToString() + ")For." ); // Open a position in one direction. elsePositionOpen (!inReverse, "act.(" + Event.ActualToString() + ")<=(" + Event.ForecastToString() + ")order." ); // Otherwise, the other direction. } Pos = calendar.GetPosAfter( time current (), position); // Get the event position in the calendar, that is, after the current time. } } #include // https://www.mql5.com/en/code/16006 #define bid symbol information double ( _symbol , SYMBOL_BID ) #define ask symbol information double ( _symbol , SYMBOL_ASK ) // Open a position using the specified annotation. TICKET_TYPE position open( const integer type, const string comment) { return (type? OrderSend ( _symbol , OP_SELL, 1 , bid, 0 , bid+inSL* _view , bid-inTP* _view , comment): OrderSend ( _symbol , OP_BUY, 1 , ask, 0 , ask-inSL* _view , ask+inTP* _view , comment)); }

    Run it once in the MT5 terminal to save all historical data (~60 Mb). They will then be available in the tester.

    Results (six years based on first half opening prices).

    Calendar - library for MetaTrader 5

    Calendar - library for MetaTrader 5


    Attachment download

    📎 string.mqh (1.77 KB)

    📎 event.mqh (20.88 KB)

    📎 calendar.mqh (30.15 KB)

    📎dst.mqh (11.46 KB)

    📎 calendar_example.mq5 (7.48 KB)

    Source: MQL5 #32430

    Verification code Refresh