WebRequest' - no one of the overloads can be applied to the function call

 

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[];

   // Make an HTTP POST request to send the message
   int res = WebRequest("POST", url, headers, postdata, 0, result, "", "");

   if (res > 0)
   {
      Print("Push notification sent successfully.");
   }
   else
   {
      Print("Error sending push notification. Error code: ", GetLastError());
   }
}
Merging the following from another post by same author with similar question

I have an error in the WebRequest section. Can anyone help me edit it

//+------------------------------------------------------------------+
//|                                                          RSI.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+


//---
  
// Define input parameters
input int RSI_Period = 6;
input double Buy_RSI_Level = 15;
input double Sell_RSI_Level = 85;
input string Telegram_API_Token = "YOUR_TELEGRAM_API_TOKEN";
input string Telegram_Chat_ID = "YOUR_CHAT_ID";

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    // Attach the RSI indicator
    int rsi_handle = iRSI(Symbol(), Period(), RSI_Period, PRICE_CLOSE);

    if (rsi_handle == INVALID_HANDLE)
    {
        Print("Error attaching RSI indicator. Error code: ", GetLastError());
        return(INIT_FAILED);
    }

    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
    // Deinitialize and clean up resources
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    double rsi_value = iRSI(Symbol(), Period(), RSI_Period, 0);

    if (rsi_value < Buy_RSI_Level)
    {
        SendTelegramMessage("Buy signal - RSI is less than 20");
        // Place your Buy order code here if needed
    }
    else if (rsi_value > Sell_RSI_Level)
    {
        SendTelegramMessage("Sell signal - RSI is greater than 80");
        // Place your Sell order code here if needed
    }
}

//+------------------------------------------------------------------+
//| Function to send a message to Telegram                            |
//+------------------------------------------------------------------+
void SendTelegramMessage(string message)
{
    string url = "https://api.telegram.org/bot" + Telegram_API_Token + "/sendMessage";
    string post_data = "chat_id=" + Telegram_Chat_ID + "&text=" + message;

    int res = WebRequest("POST", url, NULL, NULL, 0, post_data, 0, "", "", 0);

    if (res <= 0)
    {
        Print("Error sending message to Telegram. Error code: ", GetLastError());
    }
}
 
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
 
Lorentzos Roussos #:

Try this 

input error, can you help me one more time? Thank you very much


 
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

ok, thank you

 
Tung Mai Thanh #:

ok, thank you

Remove the OnStart from above

 

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);