Discord Webhook Sender
Discord is the notification channel a lot of younger traders actually watch, and its webhook API is simple - a plain POST of a JSON body to a per-channel URL - but a bare WebRequest() call gets three things wrong in practice: it builds the JSON by naive string concatenation (breaking the instant a symbol name or comment contains a quote or backslash), it ignores Discord's documented embed shape entirely, and it treats a 429 rate-limit response as a failure to give up on rather than a "try again shortly" signal. This header fixes all three. DwsJsonEscape() properly escapes quotes, backslashes and the JSON-significant whitespace controls before any string is embedded in a payload. DwsSendEmbed() builds a real Discord embed object - title, description, a packed 24-bit colour strip, optional inline fields, an optional footer - the format that actually renders as the coloured card Discord users recognise, not a plain text line. DwsPostJson() reads Discord's real 429 error body ({"message":...,"retry_after":N,"global":B}), waits the server-specified number of seconds (capped at 15 seconds so a misbehaving value can never stall the terminal indefinitely), and retries up to three times total - bounded, so a genuinely unavailable webhook still returns control to the caller rather than looping forever. Notes and limitations - WebRequest() only reaches hosts the terminal has explicitly whitelisted (Tools -> Options -> Expert Advisors). Every call fails with error 4060 until discord.com is added there - this is a terminal setting the library cannot configure for itself. - The rate-limit retry is bounded at three total attempts and a 15 second maximum single wait; a webhook that stays rate-limited or down longer than that returns a failed DwsSendResult rather than blocking further, and the caller should treat that as "try again next signal", not poll in a tight loop. - JSON building here is a hand-written escaper aimed at the specific shape of a Discord payload (content/embeds/fields), not a general JSON encoder - it correctly escapes the characters that matter for this use, not arbitrary structured data. - A webhook URL is a bearer credential in itself - anyone with the URL can post to the channel. Treat it like a password: keep it out of source control and out of screenshots.
Script · MT5 · v1.0 · Free
About Discord Webhook Sender
Discord Webhook Sender is a script for MetaTrader 5. It has 1 setting, such as Webhook url. MQL source code included.
Files in the download: DiscordWebhookSender.mq5.mqh, DiscordWebhookSender.txt, DiscordWebhookSenderDemo.ex5, DiscordWebhookSenderDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Webhook url | paste a real Discord webhook URL to test a live send (leave blank to skip) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Channels & Envelopes · Alerts · MT5 Script · MQL5 Source Code