Error 4104 in WebRequest usually indicates an issue with the format of the data being sent or the environment setup.
While it works in OnStart, OnTimer may behave differently due to things like concurrent access or improperly initialized buffers.
Make sure the Telegram URL ( https://api.telegram.org ) is added in the terminal settings (Tools > Options > Expert Advisors), and that the post[] and result[] arrays are properly sized before use.
I also recommend increasing the timeout to around 10 seconds and avoiding multiple simultaneous message sends if the timer runs frequently. With these adjustments, it should work fine from OnTimer as well.
EventSetTimer(300); is set to 300 so it is 5mins. It is long enough. But still failed to send in OnTimer for telegram messaging. It works in OnStart. I used exact same code.
void OnStart() { string token = "xxxxxI"; string chat_id = "-xxxx7658"; string url = "https://api.telegram.org/bot" + token + "/sendMessage"; string headers; char post[], result[]; string data = "chat_id=" + chat_id + "&text=Hello_from_VolumeAlert Sir!"; StringToCharArray(data, post, 0, WHOLE_ARRAY, CP_UTF8); int res = WebRequest("POST", url, headers, 5000, post, result, headers); Print("Result: ", res, " | Error: ", GetLastError()); } void OnTimer() { //--- //CheckAllSymbols(); string token = "xxxxxx"; string chat_id = "-xxxxxx58"; string url = "https://api.telegram.org/bot" + token + "/sendMessage"; string headers; char post[], result[]; string data = "chat_id=" + chat_id + "&text=Hello_from_VolumeAlert Sir!"; StringToCharArray(data, post, 0, WHOLE_ARRAY, CP_UTF8); int res = WebRequest("POST", url, headers, 5000, post, result, headers); Print("Result: ", res, " | Error: ", GetLastError()); }
Learn to search before you start to code!
Here is a whole series about how to use Telegram: https://www.mql5.com/en/search#!keyword=MQL5-Telegram&module=mql5_module_articles

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
From my mql5 program, trying to send alert message using telegram messaging service.
The message was sent successfully at OnStart function as shown below.
But the same code is used OnTimer function, it failed with error 4104. How can I send telegram message from OnTimer?