return StrToDouble(numstr);

 

Bonjour les Codeurs,


Je suis bloqué dans la création de mon EA.

Le problème se situe au niveau du bloc JSON parsing, que je n'arrive pas à résoudre.

Ces erreurs récurrentes sont relatives à la compilation de StrToDouble() et la chaîne numstr.


Les deux erreurs récurrentes sont les suivantes:

  undeclared identifier

  'numstr' - some operator expected


La ligne problématique est la suivante:

return StrToDouble(numstr);


Voici le bloc:

//-------------------- JSON parsing helpers --------------------
string RemoveCharFromString(const string src, ushort ch)
{
   string out = "";
   int L = StringLen(src);
   for(int i=0;i<L;i++)
   {
      ushort c = StringGetCharacter(src, i);
      if(c == ch) continue;
      out += StringSubstr(src, i, 1);
   }
   return out;
}
string TrimString(const string s)
{
   int L = StringLen(s);
   int start = 0, end = L - 1;
   while(start <= end)
   {
      ushort c = StringGetCharacter(s, start);
      if(c == 32 || c==9 || c==10 || c==13) start++; else break;
   }
   while(end >= start)
   {
      ushort c = StringGetCharacter(s, end);
      if(c == 32 || c==9 || c==10 || c==13) end--; else break;
   }
   if(start > end) return "";
   return StringSubstr(s, start, end-start+1);
}

double ExtractJSONNumber(const string json, const string key)
{
   int pos = StringFind(json, key);
   if(pos < 0) return 0.0;
   int colon = StringFind(json, ":", pos);
   if(colon < 0) return 0.0;
   int start = colon + 1;
   int jsonLen = StringLen(json);

   // skip spaces and quotes (double quote = ASCII 34)
   while(start < jsonLen)
   {
      ushort ch = StringGetCharacter(json, start);
      if(ch == 32 || ch == 9 || ch == 10 || ch == 13 || ch == 34) start++;
      else break;
   }

   int end = start;
   while(end < jsonLen)
   {
      ushort c = StringGetCharacter(json, end);
      if((c >= '0' && c <= '9') || c == '.' || c == '-' || c == 'e' || c == 'E' || c == '+') end++;
      else break;
   }

   if(end <= start) return 0.0;

   // declare and initialize numstr here so scope is correct
   string numstr = StringSubstr(json, start, end - start);

   // remove any lingering quotes and trim whitespace
   numstr = RemoveCharFromString(numstr, (ushort)34); // 34 = '"'
   numstr = TrimString(numstr);

   if(StringLen(numstr) == 0) return 0.0;
   return StrToDouble(numstr);
}

// Get single symbol price (regularMarketPrice) from Yahoo
double GetYahooPrice(string symbol_for_query)
{
   string json = FetchYahooQuote(symbol_for_query);
   if(StringLen(json) <= 0) return 0.0;
   // key to find: "regularMarketPrice":
   double p = ExtractJSONNumber(json, "regularMarketPrice");
   return p;
}


Pourriez-vous m'éclairer?

Je vous remercie d'avance pour votre aide !

 
StrToDouble n'existe pas. Il faut utiliser StringToDouble.
 
Alain Verleyen #:
StrToDouble n'existe pas. Il faut utiliser StringToDouble.
Merci Beaucoup à vous !