Website data fetching error.

 

Hi; I wrote this indicator that initializes and loads successfully (see image below).

indicator-successfully-loading

I get no execution error either except I get a fetching error (but no error code) 

fetching-problem

The code I use compiles without errors as well:

//+------------------------------------------------------------------+
//|                                                 BBDT-FX-News.mq4 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White

string website_data = "Loading..."; // Default data to show

int OnInit() {
   // Periodically call the function to update data
   EventSetTimer(60); // Update every 60 seconds
   return(INIT_SUCCEEDED);
}

int deinit()
  {
//----
   ObjectsDeleteAll();   
   Comment("");   
//----
   return(0);
  }

void OnTimer() {
   // Fetch data from the website
   string url = "https://www.thisisthewebsite.com/";   
   string cookie=NULL,headers;
   char post[],result[];  
   ResetLastError();   
   int timeout=5000;
   int res = WebRequest("GET",url,cookie,NULL,timeout,post,0,result,headers);

   if(res == -1) {
      website_data = "Error fetching data";
   } else {
      website_data = CharArrayToString(result);
   }
}

int OnCalculate(const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[]) {
   // Display the website data as text on the chart
   Comment("Website Data: ", website_data);

   // You can call the OnTimer function to update the data regularly
   // OnTimer();
   return(rates_total);
}

Any suggestions why I am getting a fetching error?

Much appreciate your feedback.


Thank you

 
WebRequest cannot be applied in indicators. You may check the documentation for this.
 

I must have missed that.

Thank you Yashar.