Merging the following from another post by same author with similar question
Tung Mai Thanh:
I have an error in the WebRequest section. Can anyone help me edit it
// Define your Telegram bot token and chat ID input string BotToken = "YOUR_BOT_TOKEN"; input string ChatID = "YOUR_CHAT_ID"; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Your trading logic and conditions go here // Send a push notification to Telegram string message = "Your message here"; SendTelegramMessage(message); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Deinitialization function } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { // Your trading logic and conditions go here } //+------------------------------------------------------------------+ // Function to send a message to Telegram void SendTelegramMessage(string text) { string url = "https://api.telegram.org/bot" + BotToken + "/sendMessage"; string postdata = "chat_id=" + ChatID + "&text=" + text; string headers = "Content-Type: application/x-www-form-urlencoded\r\n"; char result[]; char data[]; StringToCharArray(postdata,data,0,StringLen(postdata),CP_ACP); string result_headers=NULL; // Make an HTTP POST request to send the message int res = WebRequest("POST", url, headers,9000,data,result,result_headers); if (res > 0) { Print("Push notification sent successfully."); } else { Print("Error sending push notification. Error code: ", GetLastError()); } }
Try this
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Fernando Carreiro #:
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
ok, thank you
Please reference the documentation — Documentation on MQL5: Network Functions / WebRequest
1. Sending simple requests of type "key=value" using the header Content-Type: application/x-www-form-urlencoded.
int WebRequest( const string method, // HTTP method const string url, // URL const string cookie, // cookie const string referer, // referer int timeout, // timeout const char &data[], // the array of the HTTP message body int data_size, // data[] array size in bytes char &result[], // an array containing server response data string &result_headers // headers of server response );2. Sending a request of any type specifying the custom set of headers for a more flexible interaction with various Web services.
int WebRequest( const string method, // HTTP method const string url, // URL const string headers, // headers int timeout, // timeout const char &data[], // the array of the HTTP message body char &result[], // an array containing server response data string &result_headers // headers of server response );
In your second code, you have 10 parameters, which does not match either version of the function shown above.
int res = WebRequest("POST", url, NULL, NULL, 0, post_data, 0, "", "", 0);
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register