I can't send alert from MT5 to my telegram, please help.

 

Hello,

I'm trying to send a message to my Telegram bot using WebRequest() in MetaTrader 5, but it consistently fails with error code 4006.

Here's what I've already done:

  • Allowed WebRequest in MT5 under Tools > Options > Expert Advisors

  • Added the URL: https://api.telegram.org/

  • Restarted MT5 after setting

  • Verified my bot token and chat ID work with Postman (successfully sends messages)

  • Used StringToCharArray() and custom UrlEncode() to ensure proper data format

Sample request I'm using:

mql5 string url = "https://api.telegram.org/bot<my_token>/sendMessage";
string dta = "chat_id=<my_chat_id>&text=HelloWorld"; StringToCharArray(data, post); int res = WebRequest("POST", url, headers, 10000, post, result, responseHeaders);

But still, I get:

less [Telegram]Failed (MQL Error: 4006, HTTP Status: 0)

Is there any recent change in MT5 that could block WebRequests to external APIs?
Or do I need to enable something more in Windows/Firewall settings?

Thanks in advance for any help! 🙏

Bots: An introduction for developers
  • core.telegram.org
Bots are small applications that run entirely within the Telegram app. Users interact with bots through flexible interfaces…
 
rhyme-prime:

Error 4006 along with HTTP code 0 usually means that the request never actually gets established, often due to a network-level block (firewall, antivirus, or system settings) or SSL certificate issues. Since you’ve already added the URL correctly in the WebRequest() settings and confirmed that the bot and chat ID work via Postman, I’d suggest checking whether MetaTrader has permission to access the internet through port 443. You could also try sending a simpler request, without manually encoding parameters, to rule out any issues with your UrlEncode() function.

Lastly, take a look at the terminal logs (in the Journal or Experts tab), as they sometimes provide more detailed information about why the connection failed. If it still doesn't work, feel free to share a snippet of your code here so we can take a closer look and help you further.

 
Miguel Angel Vico Alba #:

Error 4006 along with HTTP code 0 usually means that the request never actually gets established, often due to a network-level block (firewall, antivirus, or system settings) or SSL certificate issues. Since you’ve already added the URL correctly in the WebRequest() settings and confirmed that the bot and chat ID work via Postman, I’d suggest checking whether MetaTrader has permission to access the internet through port 443. You could also try sending a simpler request, without manually encoding parameters, to rule out any issues with your UrlEncode() function.

Lastly, take a look at the terminal logs (in the Journal or Experts tab), as they sometimes provide more detailed information about why the connection failed. If it still doesn't work, feel free to share a snippet of your code here so we can take a closer look and help you furthth

thank you so much, I'll to fix it.