How to add value to char Array to do webrequest http?

 

I am trying to do http post request for practicing. I am receiving http post on my node server. However, req.body returns undefined. How can I add MA value to the http post request in this case?


//+------------------------------------------------------------------+
//|                                                  aa.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  { 
   string cookie=NULL,headers; 
   double   MA30  =  iMA(NULL,PERIOD_CURRENT,14,0,MODE_SMA,PRICE_CLOSE);
   char   post[],result[]; 
   string url="http://localhost:100/"; 
   StringToCharArray(DoubleToString(MA30,8),post, 0, 0,65001);
   
   
   ResetLastError(); 
   int res=WebRequest("POST",url,cookie,NULL,10000,post,ArraySize(post),result,headers); 
   
   
   if(res==-1) 
     { 
      Print("Error in WebRequest. Error code  =",GetLastError()); 
      //--- Perhaps the URL is not listed, display a message about the necessity to add the address 
      MessageBox("Add the address '"+url+"' to the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION); 
     } 
   else 
     { 
      if(res==200) 
        { 
         //--- Successful download 
         PrintFormat("The file has been successfully downloaded, File size %d byte.",ArraySize(result)); 
         //PrintFormat("Server headers: %s",headers); 
         //--- Saving the data to a file 
         int filehandle=FileOpen("url.htm",FILE_WRITE|FILE_BIN); 
         if(filehandle!=INVALID_HANDLE) 
           { 
            //--- Saving the contents of the result[] array to a file 
            FileWriteArray(filehandle,result,0,ArraySize(result)); 
            //--- Closing the file 
            FileClose(filehandle); 
           } 
         else 
            Print("Error in FileOpen. Error code =",GetLastError()); 
        } 
      else 
         PrintFormat("Downloading '%s' failed, error code %d",url,res); 
     } 
  }
//+------------------------------------------------------------------+
 

Error:

void OnTick()
  { 
   string cookie=NULL,headers; 
   double   MA30  =  iMA(NULL,PERIOD_CURRENT,14,0,MODE_SMA,PRICE_CLOSE);

the indicator handle (read the iMA help - it is of type 'int', not 'double') should be received ONCE and should be done in OnInit !!!.


Creating an iMA indicator handle, getting indicator values

Documentation on MQL5: Technical Indicators / iMA
Documentation on MQL5: Technical Indicators / iMA
  • www.mql5.com
iMA - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: