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

Hello i have a MQl5 code to conect a FastAPI an post some data, but when i try to compile always give me this error: 'WebRequest' - no one of the overloads can be applied to the function call MQL5++LM.mq5 219 11. There is a little version to test the request: 

 //+------------------------------------------------------------------+
//|                                               TestWebRequestEA.mq5|
//|                        Copyright 2024, TuNombre                   |
//|                                       https://tusitio.com         |
//+------------------------------------------------------------------+
#property strict

// Parámetros de entrada
input string testUrlPredict = "http://127.0.0.1:8000/predict";   // URL del endpoint /predict
input string testUrlRegister = "http://127.0.0.1:8000/register"; // URL del endpoint /register

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    // Realizar una solicitud de prueba al iniciar el EA
    TestWebRequest();
    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Función para realizar una solicitud WebRequest de prueba        |
//+------------------------------------------------------------------+
void TestWebRequest()
{
    // Datos de prueba para /predict
    string predictDataStr = "{\"open\": 1.2345, \"high\": 1.2350, \"low\": 1.2330, \"close\": 1.2340, \"volume\": 1000, \"trix\": 0.5}";
    char predictData[];
    StringToCharArray(predictDataStr, predictData);
    
    string predictHeaders = "Content-Type: application/json";
    string predictResponse;
    int predictRes = WebRequest("POST", testUrlPredict, predictHeaders, 5000, predictData, predictResponse);
    
    if(predictRes == 200)
    {
        Print("Respuesta exitosa de /predict: " + predictResponse);
        
        // Parsear la respuesta para obtener "probability"
        double probability = 0.0;
        int start = StringFind(predictResponse, ":");
        int end = StringFind(predictResponse, "}");
        if(start != -1 && end != -1 && end > start)
        {
            string probabilityStr = StringSubstr(predictResponse, start + 1, end - start - 1);
            probability = StringToDouble(probabilityStr);
            Print("Probabilidad obtenida: ", probability);
        }
        else
        {
            Print("Error: Formato de respuesta inesperado en /predict.");
        }
        
        // Datos de prueba para /register
        string registerDataStr = StringFormat(
            "{\"price\": %.5f, \"lotSize\": %.2f, \"takeProfit\": %.5f, \"stopLoss\": %.5f, \"prediccionML\": %.2f, \"resistencia\": %.5f, \"soporte\": %.5f, \"timestamp\": \"%s\"}",
            1.2345, 0.1, 1.2400, 1.2300, probability, 1.2350, 1.2330, "2024-10-28 15:30"
        );
        char registerData[];
        StringToCharArray(registerDataStr, registerData);
        
        string registerHeaders = "Content-Type: application/json";
        string registerResponse;
        int registerRes = WebRequest("POST", testUrlRegister, registerHeaders, 5000, registerData, registerResponse);
        
        if(registerRes == 200)
        {
            Print("Respuesta exitosa de /register: " + registerResponse);
        }
        else
        {
            Print("Error en WebRequest a /register. Código de respuesta: " + IntegerToString(registerRes));
        }
    }
    else
    {
        Print("Error en WebRequest a /predict. Código de respuesta: " + IntegerToString(predictRes));
    }
}
 
Gaizka Martinez #: but when i try to compile always give me this error: 'WebRequest' - no one of the overloads can be applied to the function call MQL5++LM.mq5

Perhaps you should read the manual, or press F1 in the editor.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Call requires a char array.
Your code
Documentation
int predictRes = WebRequest(
"POST", 
testUrlPredict,
predictHeaders, 
5000, 
predictData, 
                           
predictResponse
);
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
   );
 
'WebRequest' - no one of the overloads can be applied to the function call Lumintu project.mq5 94 18 . anyone help me please ?
 
Susanto Adhi Pranoto #:
'WebRequest' - no one of the overloads can be applied to the function call Lumintu project.mq5 94 18 . anyone help me please ?

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 
   );
string jsonDataStr = "{}"; // your json string
char jsonData[];
StringToCharArray(jsonDataStr, jsonData);
good luck