[{"data":1,"prerenderedAt":732},["ShallowReactive",2],{"\u002Fguides\u002Fnews-filter-mt5-expert-advisor-built-in-calendar-or-api":3,"\u002Fguides\u002Fnews-filter-mt5-expert-advisor-built-in-calendar-or-api-surround":723},{"id":4,"title":5,"authors":6,"badge":12,"body":14,"date":711,"description":712,"draft":713,"extension":714,"image":715,"meta":717,"navigation":236,"path":718,"seo":719,"stem":720,"updated":721,"__hash__":722},"posts\u002F3.guides\u002F42.news-filter-mt5-expert-advisor-built-in-calendar-or-api.md","News Filter in MT5: the Built-in Calendar or an API?",[7],{"name":8,"to":9,"avatar":10},"ShowMyTrades Team","https:\u002F\u002Fshowmytrades.com",{"src":11},"\u002Ficon-512.png",{"label":13},"Automation",{"type":15,"value":16,"toc":702},"minimark",[17,26,29,34,156,160,171,357,364,379,382,415,419,422,430,457,504,519,523,592,595,599,607,611,617,633,647,653,657,683,686,698],[18,19,20,21,25],"p",{},"If you write Expert Advisors for MetaTrader 5 you have a choice that MT4 users do not: the terminal ships an ",[22,23,24],"strong",{},"economic calendar",", and MQL5 can read it with a handful of functions. No download, no URL to allow, nothing to parse.",[18,27,28],{},"So why would anyone use an external API? Because the built-in calendar has edges, and three of them matter for a news filter. This guide shows the native code, then the API code, and when to pick which.",[30,31,33],"h2",{"id":32},"️-the-two-options-side-by-side","⚖️ The Two Options Side by Side",[35,36,37,56],"table",{},[38,39,40],"thead",{},[41,42,43,46,49],"tr",{},[44,45],"th",{},[44,47,48],{},"Built-in MQL5 calendar",[44,50,51],{},[52,53,55],"a",{"href":54},"\u002Fdocs\u002Fapi\u002Feconomic-calendar","ShowMyTrades calendar API",[57,58,59,75,86,97,108,119,134,145],"tbody",{},[41,60,61,65,68],{},[62,63,64],"td",{},"Setup",[62,66,67],{},"None",[62,69,70,71,74],{},"Allow ",[72,73,9],"code",{}," under Tools → Options → Expert Advisors",[41,76,77,80,83],{},[62,78,79],{},"Data source",[62,81,82],{},"MetaQuotes, delivered by the broker's server",[62,84,85],{},"Public calendar sources, assembled by ShowMyTrades",[41,87,88,91,94],{},[62,89,90],{},"Available on",[62,92,93],{},"Brokers that enable it (most do; some white-label servers do not)",[62,95,96],{},"Any broker, any terminal with internet",[41,98,99,102,105],{},[62,100,101],{},"Works in MT4 too",[62,103,104],{},"No",[62,106,107],{},"Yes, same file",[41,109,110,113,116],{},[62,111,112],{},"Works in the strategy tester",[62,114,115],{},"Yes, with history",[62,117,118],{},"No (no network in the tester)",[41,120,121,124,127],{},[62,122,123],{},"Time zone",[62,125,126],{},"Trade server time, at an offset from UTC you have to work out",[62,128,129,130,133],{},"UTC (",[72,131,132],{},"ts"," in Unix seconds), and every response carries the server's current UTC time, so the EA never depends on the broker's or the VPS's clock",[41,135,136,139,142],{},[62,137,138],{},"Values",[62,140,141],{},"Forecast, previous, actual, with revisions",[62,143,144],{},"Forecast, previous, actual",[41,146,147,150,153],{},[62,148,149],{},"Cost",[62,151,152],{},"Free",[62,154,155],{},"Free, no key",[30,157,159],{"id":158},"option-a-the-built-in-calendar","🧱 Option A: the Built-in Calendar",[18,161,162,163,166,167,170],{},"The function below says whether a ",[22,164,165],{},"high-impact"," release for either currency of the chart's symbol is within the pause window. Times are in trade server time, which is what ",[72,168,169],{},"CalendarValueHistory()"," expects.",[172,173,179],"pre",{"className":174,"code":175,"filename":176,"language":177,"meta":178,"style":178},"language-cpp shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F--- MQL5 built-in calendar: true while a high-impact release for the chart's\n\u002F\u002F--- currencies is within [-minutesBefore, +minutesAfter] of now\nbool NativeNewsTime(const int minutesBefore, const int minutesAfter, string &reason)\n{\n   reason = \"\";\n   datetime now  = TimeTradeServer();\n   datetime from = now - minutesAfter * 60;\n   datetime to   = now + minutesBefore * 60;\n\n   string currencies[2];\n   currencies[0] = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE);\n   currencies[1] = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT);\n\n   for(int c = 0; c \u003C 2; c++)\n   {\n      if(c == 1 && currencies[1] == currencies[0]) break;\n      MqlCalendarValue values[];\n      if(CalendarValueHistory(values, from, to, NULL, currencies[c]) \u003C= 0) continue;\n      for(int i = 0; i \u003C ArraySize(values); i++)\n      {\n         MqlCalendarEvent ev;\n         if(!CalendarEventById(values[i].event_id, ev)) continue;\n         if(ev.importance != CALENDAR_IMPORTANCE_HIGH) continue;\n         reason = currencies[c] + \": \" + ev.name;\n         return true;\n      }\n   }\n   return false;\n}\n","NativeNewsFilter.mqh","cpp","",[72,180,181,189,195,201,207,213,219,225,231,238,244,250,256,261,267,273,279,285,291,297,303,309,315,321,327,333,339,345,351],{"__ignoreMap":178},[182,183,186],"span",{"class":184,"line":185},"line",1,[182,187,188],{},"\u002F\u002F--- MQL5 built-in calendar: true while a high-impact release for the chart's\n",[182,190,192],{"class":184,"line":191},2,[182,193,194],{},"\u002F\u002F--- currencies is within [-minutesBefore, +minutesAfter] of now\n",[182,196,198],{"class":184,"line":197},3,[182,199,200],{},"bool NativeNewsTime(const int minutesBefore, const int minutesAfter, string &reason)\n",[182,202,204],{"class":184,"line":203},4,[182,205,206],{},"{\n",[182,208,210],{"class":184,"line":209},5,[182,211,212],{},"   reason = \"\";\n",[182,214,216],{"class":184,"line":215},6,[182,217,218],{},"   datetime now  = TimeTradeServer();\n",[182,220,222],{"class":184,"line":221},7,[182,223,224],{},"   datetime from = now - minutesAfter * 60;\n",[182,226,228],{"class":184,"line":227},8,[182,229,230],{},"   datetime to   = now + minutesBefore * 60;\n",[182,232,234],{"class":184,"line":233},9,[182,235,237],{"emptyLinePlaceholder":236},true,"\n",[182,239,241],{"class":184,"line":240},10,[182,242,243],{},"   string currencies[2];\n",[182,245,247],{"class":184,"line":246},11,[182,248,249],{},"   currencies[0] = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE);\n",[182,251,253],{"class":184,"line":252},12,[182,254,255],{},"   currencies[1] = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT);\n",[182,257,259],{"class":184,"line":258},13,[182,260,237],{"emptyLinePlaceholder":236},[182,262,264],{"class":184,"line":263},14,[182,265,266],{},"   for(int c = 0; c \u003C 2; c++)\n",[182,268,270],{"class":184,"line":269},15,[182,271,272],{},"   {\n",[182,274,276],{"class":184,"line":275},16,[182,277,278],{},"      if(c == 1 && currencies[1] == currencies[0]) break;\n",[182,280,282],{"class":184,"line":281},17,[182,283,284],{},"      MqlCalendarValue values[];\n",[182,286,288],{"class":184,"line":287},18,[182,289,290],{},"      if(CalendarValueHistory(values, from, to, NULL, currencies[c]) \u003C= 0) continue;\n",[182,292,294],{"class":184,"line":293},19,[182,295,296],{},"      for(int i = 0; i \u003C ArraySize(values); i++)\n",[182,298,300],{"class":184,"line":299},20,[182,301,302],{},"      {\n",[182,304,306],{"class":184,"line":305},21,[182,307,308],{},"         MqlCalendarEvent ev;\n",[182,310,312],{"class":184,"line":311},22,[182,313,314],{},"         if(!CalendarEventById(values[i].event_id, ev)) continue;\n",[182,316,318],{"class":184,"line":317},23,[182,319,320],{},"         if(ev.importance != CALENDAR_IMPORTANCE_HIGH) continue;\n",[182,322,324],{"class":184,"line":323},24,[182,325,326],{},"         reason = currencies[c] + \": \" + ev.name;\n",[182,328,330],{"class":184,"line":329},25,[182,331,332],{},"         return true;\n",[182,334,336],{"class":184,"line":335},26,[182,337,338],{},"      }\n",[182,340,342],{"class":184,"line":341},27,[182,343,344],{},"   }\n",[182,346,348],{"class":184,"line":347},28,[182,349,350],{},"   return false;\n",[182,352,354],{"class":184,"line":353},29,[182,355,356],{},"}\n",[18,358,359,360,363],{},"Call it from ",[72,361,362],{},"OnTick()"," exactly like any other filter:",[172,365,367],{"className":174,"code":366,"language":177,"meta":178,"style":178},"string news;\nif(NativeNewsTime(30, 30, news)) { Comment(\"News filter: \", news); return; }\n",[72,368,369,374],{"__ignoreMap":178},[182,370,371],{"class":184,"line":185},[182,372,373],{},"string news;\n",[182,375,376],{"class":184,"line":191},[182,377,378],{},"if(NativeNewsTime(30, 30, news)) { Comment(\"News filter: \", news); return; }\n",[18,380,381],{},"Three things to know before you rely on it:",[383,384,385,403,409],"ol",{},[386,387,388,391,392,394,395,398,399,402],"li",{},[22,389,390],{},"It depends on the broker."," The calendar reaches the terminal through the trade server. If ",[72,393,169],{}," returns ",[72,396,397],{},"-1"," with error ",[72,400,401],{},"5402"," on your broker, the calendar is not enabled there, and no code will fix that.",[386,404,405,408],{},[22,406,407],{},"It is server time, not UTC."," Fine on a live chart. Painful when you compare with anything else.",[386,410,411,414],{},[22,412,413],{},"It is MT5 only."," An EA you also ship for MT4 needs a second implementation.",[30,416,418],{"id":417},"option-b-the-calendar-api","🌐 Option B: the Calendar API",[18,420,421],{},"The alternative is a free HTTP endpoint that returns the next days of news for the currencies and impact you choose, as CSV or JSON:",[172,423,428],{"className":424,"code":426,"language":427,"meta":178},[425],"language-text","https:\u002F\u002Fshowmytrades.com\u002Fapi\u002Fpublic\u002Fcalendar\u002Fv1?currency=EUR,USD&impact=high&days=2&format=csv\n","text",[72,429,426],{"__ignoreMap":178},[18,431,432,433,436,437,441,442,445,446,449,450,453,454,456],{},"The include file ",[72,434,435],{},"SMT_NewsFilter.mqh"," that reads it is printed in full in the ",[52,438,440],{"href":439},"\u002Fguides\u002Fadd-a-news-filter-to-your-mt4-expert-advisor","MT4 guide"," and in the ",[52,443,444],{"href":54},"API reference",". ",[22,447,448],{},"It compiles in MQL5 unchanged",": save it in ",[72,451,452],{},"MQL5\\Include",", allow ",[72,455,9],{}," in Tools → Options → Expert Advisors, and call:",[172,458,460],{"className":174,"code":459,"language":177,"meta":178,"style":178},"#include \u003CSMT_NewsFilter.mqh>\n\nvoid OnTick()\n{\n   string news;\n   if(SMT_IsNewsTime(news)) { Comment(\"News filter active: \", news); return; }\n   Comment(\"\");\n   \u002F\u002F ... your entry logic ...\n}\n",[72,461,462,467,471,476,480,485,490,495,500],{"__ignoreMap":178},[182,463,464],{"class":184,"line":185},[182,465,466],{},"#include \u003CSMT_NewsFilter.mqh>\n",[182,468,469],{"class":184,"line":191},[182,470,237],{"emptyLinePlaceholder":236},[182,472,473],{"class":184,"line":197},[182,474,475],{},"void OnTick()\n",[182,477,478],{"class":184,"line":203},[182,479,206],{},[182,481,482],{"class":184,"line":209},[182,483,484],{},"   string news;\n",[182,486,487],{"class":184,"line":215},[182,488,489],{},"   if(SMT_IsNewsTime(news)) { Comment(\"News filter active: \", news); return; }\n",[182,491,492],{"class":184,"line":221},[182,493,494],{},"   Comment(\"\");\n",[182,496,497],{"class":184,"line":227},[182,498,499],{},"   \u002F\u002F ... your entry logic ...\n",[182,501,502],{"class":184,"line":233},[182,503,356],{},[18,505,506,507,510,511,514,515,518],{},"It downloads once every 15 minutes, compares in UTC with ",[72,508,509],{},"TimeGMT()",", and keeps the inputs (",[72,512,513],{},"SMT_Currencies",", ",[72,516,517],{},"SMT_Impact",", minutes before and after) in the EA's settings dialog.",[30,520,522],{"id":521},"which-one-to-pick","🎯 Which One to Pick",[35,524,525,535],{},[38,526,527],{},[41,528,529,532],{},[44,530,531],{},"Your situation",[44,533,534],{},"Pick",[57,536,537,547,558,570,584],{},[41,538,539,542],{},[62,540,541],{},"MT5 only, broker has the calendar, you backtest the filter",[62,543,544],{},[22,545,546],{},"Built-in",[41,548,549,552],{},[62,550,551],{},"The same EA for MT4 and MT5",[62,553,554,557],{},[22,555,556],{},"API",": one file, one behaviour",[41,559,560,566],{},[62,561,562,563,565],{},"Broker without the calendar (",[72,564,401],{},")",[62,567,568],{},[22,569,556],{},[41,571,572,575],{},[62,573,574],{},"You also run cBots on cTrader",[62,576,577,579,580],{},[22,578,556],{},": the ",[52,581,583],{"href":582},"\u002Fguides\u002Fadd-a-news-filter-to-a-ctrader-cbot","same data on cTrader",[41,585,586,589],{},[62,587,588],{},"You want to log the news with the trade for later review",[62,590,591],{},"Either; the API gives UTC timestamps that match the rest of your logs",[18,593,594],{},"Nothing stops you from using both: the built-in calendar when it answers, the API when it does not. In practice one is enough.",[30,596,598],{"id":597},"backtesting-a-news-filter","🧪 Backtesting a News Filter",[18,600,601,602,606],{},"The built-in calendar is the only one of the two that works in the strategy tester, because the tester has no internet. Even there, be careful with what a backtest of a news filter proves: the test uses the calendar as it is known ",[603,604,605],"em",{},"today",", with revised times and the events that were added after the fact. A live filter only knows what was scheduled at the time.",[30,608,610],{"id":609},"faq","❓ FAQ",[18,612,613,616],{},[22,614,615],{},"Is the built-in MT5 calendar free?","\nYes. It is part of the terminal, delivered through your broker's server, with no setting to enable on your side.",[18,618,619,625,626,629,630,632],{},[22,620,621,622,624],{},"Why does ",[72,623,169],{}," return nothing on my broker?","\nSome servers, often white-label ones, do not relay the calendar. Check ",[72,627,628],{},"GetLastError()",": ",[72,631,401],{}," means the calendar is not available. Use the API in that case.",[18,634,635,638,639,642,643,646],{},[22,636,637],{},"Can I filter by the currencies of a different symbol?","\nYes. Pass the currency codes you want instead of reading them from ",[72,640,641],{},"_Symbol",". The API version takes them as an input string, ",[72,644,645],{},"EUR,USD,GBP",".",[18,648,649,652],{},[22,650,651],{},"Does the API need an account?","\nNo. No key, no login. The limit is 600 requests per minute per IP address, far above what any number of charts needs at one request every 15 minutes.",[30,654,656],{"id":655},"related","🔗 Related",[658,659,660,666,672,677],"ul",{},[386,661,662,665],{},[52,663,664],{"href":439},"How to add a news filter to your MT4 Expert Advisor",": the full include file",[386,667,668,671],{},[52,669,670],{"href":54},"Economic calendar API reference",": parameters, formats, limits",[386,673,674],{},[52,675,676],{"href":582},"News filter for a cTrader cBot",[386,678,679],{},[52,680,682],{"href":681},"\u002Fglossary\u002Fwhat-is-an-expert-advisor","What is an Expert Advisor",[684,685],"hr",{},[18,687,688,689,445,693,697],{},"Whichever calendar you choose, the result shows in the track record: fewer trades opened into a spike, and a smoother ",[52,690,692],{"href":691},"\u002Fglossary\u002Fwhat-is-drawdown","drawdown",[52,694,696],{"href":695},"\u002Fsignup","Track your MT5 account free"," and see it on the chart.",[699,700,701],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":178,"searchDepth":191,"depth":191,"links":703},[704,705,706,707,708,709,710],{"id":32,"depth":191,"text":33},{"id":158,"depth":191,"text":159},{"id":417,"depth":191,"text":418},{"id":521,"depth":191,"text":522},{"id":597,"depth":191,"text":598},{"id":609,"depth":191,"text":610},{"id":655,"depth":191,"text":656},"2026-10-17T00:00:00.000Z","MetaTrader 5 ships an economic calendar that Expert Advisors can read with no download. When it is enough, when it is not, and how to use a free calendar API instead, with MQL5 code for both.",false,"md",{"src":716},"\u002Fimages\u002Fblog\u002Fnews-filter-mt5-expert-advisor-built-in-calendar-or-api-hero.svg",{},"\u002Fguides\u002Fnews-filter-mt5-expert-advisor-built-in-calendar-or-api",{"title":5,"description":712},"3.guides\u002F42.news-filter-mt5-expert-advisor-built-in-calendar-or-api",null,"KG1EuuCYR476gs9S3HV43LPZ_pY3-EgYyEmGIJUtbjE",[724,728],{"title":725,"path":439,"stem":726,"description":727,"children":-1},"How to Add a News Filter to Your MT4 Expert Advisor","3.guides\u002F41.add-a-news-filter-to-your-mt4-expert-advisor","MetaTrader 4 has no economic calendar for Expert Advisors. This guide adds one in ten minutes: a free calendar API, one include file, one function to call before every entry. Full MQL4 code, no API key.",{"title":729,"path":582,"stem":730,"description":731,"children":-1},"How to Add a News Filter to a cTrader cBot (Cloud Included)","3.guides\u002F43.add-a-news-filter-to-a-ctrader-cbot","cTrader has no calendar API for cBots, and cTrader Cloud blocks HTTP requests. Here is a news filter that works on the desktop and in the cloud, with a free calendar over WebSocket and the full C# code.",1792249019817]