The library has been updated to allow for event modification.
#include <fxsaber\Calendar\Calendar.mqh> // https://www.mql5.com/ru/code/32430voidOnStart()
{
CALENDAR Calendar;
conststring Currencies[] = {SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE),
SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT)};
// Took upcoming important events by symbol currencies.
Calendar.Set(Currencies);
Print(Calendar.ToString()); // Printed them out.
EVENT Events[];
if (Calendar.GetEvents(Events) > 0) // Got all events in internal format.
{
Events[0].Importance = (ENUM_CALENDAR_EVENT_IMPORTANCE)27; // Changed the importance of the event.
Calendar = Events; // Put events on the Calendar.Print(Calendar.ToString()); // Printed them out.
}
}
Looks like I got a Calendar corrector that matches the trading server.
#property script_show_inputsinputulong inEventID = 840030006; // EventIDinputstring inName = ""; // Name -> EventID (Nonfarm Payrolls -> 840030016)inputdatetime inFrom = D'2020.01.01';
inputbool inDST = true;
voidOnStart()
{
CALENDAR Calendar;
if (inName == "")
{
Calendar.Set(inEventID);
Calendar.FilterByTime(inFrom, TimeCurrent());
Calendar.CorrectTime(); // Bypass MQL-calendar peculiarities: https://www.mql5.com/ru/forum/444094/page14#comment_46213385if (inDST)
Calendar.DST(); // Call if the trade server is synchronised with European time.for (int i = Calendar.GetAmount() - 1; i >= 0; i--)
{
const EVENT Event = Calendar[i];
constdatetime ChartNews = ChartNewsTime(Event.time); // https://www.mql5.com/ru/forum/357793/page5#comment_44225999if (Event.time != ChartNews)
Print("-" + (string)Event.EventID + ": " + TimeToString(ChartNews) + " != " + Event.ToString());
elsePrint("+" + (string)Event.EventID + ": " + TimeToString(ChartNews) + " == " + Event.ToString());
}
}
else// Get EventID by name.
{
string Currencies[2];
// Get the currencies of the current character.
Currencies[0] = ::SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE);
Currencies[1] = ::SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT);
if (Calendar.Set(Currencies, CALENDAR_IMPORTANCE_MODERATE, inFrom) && Calendar.FilterByName(inName))
for (int i = Calendar.GetAmount() - 1; i >= 0; i--)
Print((string)Calendar[i].EventID + ": " + Calendar[i].ToString());
}
}
Result.
+840030016: 2023.04.0715:30 == 2023.04.0715:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 236 K | -8 K | 311 K | 326 K
+840030016: 2023.03.1015:30 == 2023.03.1015:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 311 K | -35 K | 517 K | 504 K
+840030016: 2023.02.0315:30 == 2023.02.0315:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 517 K | 16 K | 223 K | 260 K
+840030016: 2023.01.0615:30 == 2023.01.0615:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 223 K | 57 K | 263 K | 256 K
+840030016: 2022.12.0215:30 == 2022.12.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 263 K | -30 K | 261 K | 284 K
+840030016: 2022.11.0414:30 == 2022.11.0414:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 261 K | -97 K | 263 K | 315 K
+840030016: 2022.10.0715:30 == 2022.10.0715:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 263 K | 33 K | 315 K |
+840030016: 2022.09.0215:30 == 2022.09.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 315 K | 156 K | 528 K | 526 K
Matches the Web-calendar. If anyone sees any obvious inconsistencies, let me know.
Now it seems to be correct to use the calendar for backtests.
fxsaber #: You can't compare by 840200001-event, because it has a weak influence on quotes - the time of the left column may be incorrectly calculated.
Thanks, I took a closer look and understand the proposed method.
I think for some cases it would be more interesting to look at a certain time range (before and after the event) to see how much the price has changed.
After updating the library Calendar should be synchronised with the quotes history on any broker.
Check (run on EURUSD).
#property script_show_inputsinputulong inEventID = 840030016; // EventID (840030016 - Nonfarm Payrolls)inputdatetime inFrom = D'2020.01.01';
// Time bar size.double GetBarSize( constdatetime Time )
{
MqlRates Rates[];
return(CopyRates(_Symbol, PERIOD_M1, iBarShift(_Symbol, PERIOD_M1, Time), 1, Rates) != 1 ? 0 : Rates[0].high - Rates[0].low);
}
// Time of the largest bar by size (by time from the array).datetime GetMaxBarSizeTime( constdatetime &Times[] )
{
double Values[];
for (int i = ArrayResize(Values, ArraySize(Times)) - 1; i >= 0; i--)
Values[i] = GetBarSize(Times[i]);
return(Times[ArrayMaximum(Values)]);
}
// Most likely time of news on price data (strong reaction).datetime ChartNewsTime( constdatetime &Time )
{
datetime Times[3];
Times[0] = Time;
Times[1] = Times[0] - 3600;
Times[2] = Times[0] + 3600;
return(GetMaxBarSizeTime(Times));
}
#include <fxsaber\Calendar\Calendar.mqh> // https://www.mql5.com/ru/code/32430#define PRINT(A) Print(#A + " = " + (string)(A))
voidOnStart()
{
PRINT(AccountInfoString(ACCOUNT_SERVER));
PRINT(TimeTradeServer());
PRINT(DST::IsEurope()); // European DST Regulation.
PRINT(DST::GetRollover()); // Rollover Time.
PRINT(DST::TimeServerGMTOffset()); // GMT server offset.
CALENDAR Calendar;
Calendar.Set(inEventID);
Calendar.FilterByTime(inFrom, TimeCurrent());
Calendar.AutoDST();for (int i = Calendar.GetAmount() - 1; i >= 0; i--)
{
const EVENT Event = Calendar[i];
constdatetime ChartNews = ChartNewsTime(Event.time);
if (Event.time != ChartNews)
Print("-" + (string)Event.EventID + ": " + TimeToString(ChartNews) + " != " + Event.ToString());
elsePrint("+" + (string)Event.EventID + ": " + TimeToString(ChartNews) + " == " + Event.ToString());
}
}
Result.
AccountInfoString(ACCOUNT_SERVER) = RannForex-Server
TimeTradeServer() = 2024.03.1409:26:54
DST::IsEurope() = 1
DST::GetRollover() = 2024.03.1323:00:00
DST::TimeServerGMTOffset() = -7200
+840030016: 2024.03.0815:30 == 2024.03.0815:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
+840030016: 2024.02.0215:30 == 2024.02.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
+840030016: 2024.01.0515:30 == 2024.01.0515:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
+840030016: 2023.12.0815:30 == 2023.12.0815:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K |
+840030016: 2023.11.0314:30 == 2023.11.0314:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
+840030016: 2023.10.0615:30 == 2023.10.0615:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
+840030016: 2023.09.0115:30 == 2023.09.0115:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 187 K | 12 K | 187 K | 157 K
+840030016: 2023.08.0415:30 == 2023.08.0415:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 187 K | -1 K | 209 K | 185 K
+840030016: 2023.07.0715:30 == 2023.07.0715:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 209 K | -19 K | 339 K | 306 K
+840030016: 2023.06.0215:30 == 2023.06.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 339 K | 1 K | 253 K | 294 K
+840030016: 2023.05.0515:30 == 2023.05.0515:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 253 K | 23 K | 236 K | 165 K
+840030016: 2023.04.0715:30 == 2023.04.0715:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 236 K | -8 K | 311 K | 326 K
+840030016: 2023.03.1015:30 == 2023.03.1015:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 311 K | -35 K | 517 K | 504 K
+840030016: 2023.02.0315:30 == 2023.02.0315:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 517 K | 16 K | 223 K | 260 K
+840030016: 2023.01.0615:30 == 2023.01.0615:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 223 K | 57 K | 263 K | 256 K
+840030016: 2022.12.0215:30 == 2022.12.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 263 K | -30 K | 261 K | 284 K
+840030016: 2022.11.0414:30 == 2022.11.0414:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 261 K | -97 K | 263 K | 315 K
+840030016: 2022.10.0715:30 == 2022.10.0715:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 263 K | 33 K | 315 K |
+840030016: 2022.09.0215:30 == 2022.09.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 315 K | 156 K | 528 K | 526 K
+840030016: 2022.08.0515:30 == 2022.08.0515:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 528 K | -19 K | 372 K | 398 K
+840030016: 2022.07.0815:30 == 2022.07.0815:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 372 K | -229 K | 390 K | 384 K
+840030016: 2022.06.0315:30 == 2022.06.0315:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 390 K | -19 K | 428 K | 436 K
+840030016: 2022.05.0615:30 == 2022.05.0615:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 428 K | 317 K | 431 K | 428 K
+840030016: 2022.04.0115:30 == 2022.04.0115:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 431 K | 80 K | 678 K | 750 K
+840030016: 2022.03.0415:30 == 2022.03.0415:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 678 K | -413 K | 467 K | 481 K
+840030016: 2022.02.0415:30 == 2022.02.0415:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 467 K | -192 K | 199 K | 510 K
+840030016: 2022.01.0715:30 == 2022.01.0715:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | 379 K | 210 K | 249 K
+840030016: 2021.12.0315:30 == 2021.12.0315:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 210 K | 330 K | 531 K | 546 K
+840030016: 2021.11.0514:30 == 2021.11.0514:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 531 K | -54 K | 194 K | 312 K
+840030016: 2021.10.0815:30 == 2021.10.0815:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 194 K | -302 K | 235 K | 366 K
+840030016: 2021.09.0315:30 == 2021.09.0315:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 235 K | 23 K | 943 K | 1053 K
+840030016: 2021.08.0615:30 == 2021.08.0615:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 943 K | 381 K | 850 K | 938 K
+840030016: 2021.07.0215:30 == 2021.07.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 850 K | 3 K | 559 K | 583 K
+840030016: 2021.06.0415:30 == 2021.06.0415:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 559 K | -396 K | 266 K | 278 K
+840030016: 2021.05.0715:30 == 2021.05.0715:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 266 K | -1 K | 916 K | 770 K
+840030016: 2021.04.0215:30 == 2021.04.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 916 K | 409 K | 379 K | 468 K
+840030016: 2021.03.0515:30 == 2021.03.0515:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 379 K | -137 K | 49 K | 166 K
+840030016: 2021.02.0515:30 == 2021.02.0515:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 49 K | -497 K | -140 K | -227 K
+840030016: 2021.01.0815:30 == 2021.01.0815:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | -140 K | 207 K | 245 K | 336 K
+840030016: 2020.12.0415:30 == 2020.12.0415:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 245 K | 528 K | 638 K | 610 K
+840030016: 2020.11.0615:30 == 2020.11.0615:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 638 K | -76324 K | 661 K | 672 K
-840030016: 2020.10.0216:30 != 2020.10.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 661 K | 78356 K | 1371 K | 1489 K
+840030016: 2020.09.0415:30 == 2020.09.0415:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 1371 K | -74433 K | 1763 K | 1734 K
+840030016: 2020.08.0715:30 == 2020.08.0715:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 1763 K | 4511 K | 4800 K | 4791 K
+840030016: 2020.07.0215:30 == 2020.07.0215:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 4800 K | -12034 K | 2509 K | 2699 K
+840030016: 2020.06.0515:30 == 2020.06.0515:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 2509 K | -10000 K | -20500 K | -20687 K
+840030016: 2020.05.0815:30 == 2020.05.0815:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | -20500 K | 139 K | -701 K | -870 K
+840030016: 2020.04.0315:30 == 2020.04.0315:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | -701 K | 163 K | 273 K | 275 K
+840030016: 2020.03.0615:30 == 2020.03.0615:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 273 K | 161 K | 225 K | 273 K
+840030016: 2020.02.0715:30 == 2020.02.0715:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 225 K | 161 K | 145 K | 147 K
+840030016: 2020.01.1015:30 == 2020.01.1015:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 145 K | 168 K | 266 K | 256 K
It will be necessary to check the correctness during the autumn Europe/USA unsynchronisation.
Now you can use the calendar in backtests (the sample EA in the delivery has been updated).
I have a bad feeling about the correctness of this function.
Using limits from calculus: the output range for (x % 24) is 0 to 23, so the output range of the function is -3 to 20. therefore a server of -5 cannot be represented.
I have a bad feeling about the correctness of this function.
Using limits from calculus: the output range for (x % 24) is 0 to 23, so the output range of the function is -3 to 20. therefore a server of -5 cannot be represented.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
On the relevance of calendar data.
For comparison the work of another source.
Result.
Forum on trading, automated trading systems and testing trading strategies
Libraries: Calendar
fxsaber, 2023.04.13 00:07 pm.
Looks like I got a Calendar corrector that matches the trading server.
Result.
Matches the Web-calendar. If anyone sees any obvious inconsistencies, let me know.
Now it seems to be correct to use the calendar for backtests.
I got this result:
Looks like it turned out to be a Calendar corrector that matches the trade server.
Result.
Matches the Web Calendar. If anyone sees any obvious discrepancies, let me know.
Now it seems to be correct to use the calendar for backtests.
Inconsistencies are seen all over the place:
//---
Please check this for yourself as well.
Inconsistencies are observed across the board
You can't compare by 840200001-event, because it has a weak influence on quotes - the time of the left column may be incorrectly calculated.
Thanks, I took a closer look and understand the proposed method.
I think for some cases it would be more interesting to look at a certain time range (before and after the event) to see how much the price has changed.
Inconsistencies are observed
After updating the library Calendar should be synchronised with the quotes history on any broker.
Check (run on EURUSD).
Result.
It will be necessary to check the correctness during the autumn Europe/USA unsynchronisation.
Now you can use the calendar in backtests (the sample EA in the delivery has been updated).
ZY I recommend you to look at the works of this author.
I have a bad feeling about the correctness of this function.
Using limits from calculus: the output range for (x % 24) is 0 to 23, so the output range of the function is -3 to 20. therefore a server of -5 cannot be represented.
I have a bad feeling about the correctness of this function.
Using limits from calculus: the output range for (x % 24) is 0 to 23, so the output range of the function is -3 to 20. therefore a server of -5 cannot be represented.
You are right, thank you.
subtract directly from 12:30 (instead of -3 + 31*/2):