MetaTrader 5 and 4: send alerts to a webhook that get retried
Short answer: MetaTrader 5 and 4 send HTTP requests with WebRequest(), from an Expert Advisor or a script only (MQL5 reference: WebRequest). The call blocks your EA until the server answers and sends once, with no retry. If your server is slow or down, the alert is lost. Answer fast, or send it to a queue that retries.
How WebRequest works
- You must add the server to Tools → Options → Expert Advisors → Allow WebRequest for listed URL. Otherwise the call returns -1.
- It works in Expert Advisors and scripts, not in indicators (error 4014) and not in the Strategy Tester.
- It is synchronous: your EA waits for the reply, up to the timeout you pass.
- It sends one request. There is no built-in retry.
Why alerts get lost
- Not on the allowed list. The URL is missing from the Expert Advisors options, so every call fails.
- Called from an indicator. The code runs, but WebRequest() is refused.
- Your server is down or restarting. The one request fails and nothing sends it again.
- Slow replies. A long timeout freezes your EA; a short one gives up on a slow server.
Set it up with HoldAlarms
- Start a trial and copy the webhook URL from your dashboard. It looks like
https://api.holdalarms.com/hook/<your token>. - Add your own endpoint as a destination in HoldAlarms.
- In MetaTrader, add
https://api.holdalarms.comto Allow WebRequest for listed URL. - Copy
HoldAlarms.mqhintoMQL5/Include(orMQL4/Include), add#include <HoldAlarms.mqh>to your EA and callHoldAlarmsAlert(url, "buy")orHoldAlarmsSend(url, body). - Run the HoldAlarmsTest script once and check Recent alerts on your dashboard.
Full reference: Docs: MetaTrader setup.
What HoldAlarms does
We answer MetaTrader with HTTP 200 once the alert is queued, then deliver it to your endpoint in the background. Your endpoint gets 10 seconds per attempt. If it fails, we retry up to 5 times, 2 to 60 seconds apart (permanent errors such as 401 or 403 aren't retried). Retries finish within about 3 minutes, or up to about 6 if your server asks for longer waits with Retry-After. After that the alert is parked in a dead-letter queue and you get an email.
Two honest limits: we add a hop, so HoldAlarms doesn't cut latency; and a delivered alert means your endpoint accepted it, not that your app finished processing it. Starter is €19/mo and Ops €49/mo.
Questions
Can a MetaTrader indicator send a webhook?
No. WebRequest() only works in Expert Advisors and scripts. Called from an indicator it fails with error 4014.
Why does WebRequest return -1?
Most often the URL is not on the allowed list. Open Tools, Options, Expert Advisors, tick Allow WebRequest for listed URL and add https://api.holdalarms.com.
Does WebRequest work in the Strategy Tester?
No. MetaTrader does not run WebRequest() in the Strategy Tester, so test on a demo or live chart.
Does MetaTrader retry a failed webhook?
No. WebRequest() sends one request and returns. Our free snippet tries twice on a network error or 5xx. HoldAlarms then retries your own endpoint up to 5 times.
Does HoldAlarms reduce latency?
No. HoldAlarms adds a hop, so each alert reaches your endpoint slightly later than it would directly. What it gives you is an answer to MetaTrader as soon as the alert is queued, and 5 retries to your endpoint.
More guides
- NinjaTrader 8 webhook alerts
- TrendSpider webhook alerts
- Webhook alert delivery: slow or down endpoints
- All guides
- All HoldAlarms questions
HoldAlarms is not affiliated with MetaQuotes. MetaTrader is a trademark of MetaQuotes Ltd.