MQL5 Group Name (Symbol Type)

I am porting my code to MQL5

I have a requirement to access the brokers group name (System type or the category that a symbol belongs to). The code below works in MT4 - I found it on the web.

Anybody know how to get the same information in MQL5?

//+------------------------------------------------------------------+
//| Get SymbolType from SymbolsLib.mqh                               |
//+------------------------------------------------------------------+ 
string SymbolType(string SymbolName)
  {
   int GroupNumber=-1;
   string SymbolGroup="";

   int hFile=FileOpenHistory("symbols.raw",FILE_BIN|FILE_READ);
   if(hFile < 0) return("");

   int SymbolsNumber=int(FileSize(hFile)/1936);

   for(int i=0; i<SymbolsNumber; i++)
     {
      if(FileReadString(hFile,12)==SymbolName)
        {

         FileSeek(hFile,1936*i+100,SEEK_SET);
         GroupNumber=FileReadInteger(hFile);

         break;
        }
      FileSeek(hFile,1924,SEEK_CUR);
     }

   FileClose(hFile);

   if(GroupNumber < 0) return("");

   hFile=FileOpenHistory("symgroups.raw",FILE_BIN|FILE_READ);
   if(hFile < 0) return("");

   FileSeek(hFile,80*GroupNumber,SEEK_SET);
   SymbolGroup=FileReadString(hFile,16);

   FileClose(hFile);
   return(SymbolGroup);
  }

This code is obsolete, as in mql5, you can also use SYMBOL_PATH in mql4.

   string path = SymbolInfoString("EURUSD",SYMBOL_PATH);

Path contains: Forex/EURUSD

Simple - many thanks Brittany

//+------------------------------------------------------------------+
//|Get the Brokers Group Name for the Symbol                         |
//+------------------------------------------------------------------+        
string symbolType(string symbol)
  {
   string outVal=NULL;
   string path=NULL;
   ResetLastError();//zero last error
   SymbolInfoString(symbol,SYMBOL_PATH,outVal);
   if(!GetLastError())
     {
      path=SymbolInfoString(symbol,SYMBOL_PATH);
      StringReplace(path,symbol,"");
     }   
   else
      Alert("Cannot Find: ",symbol," Path");
   return path;
  }
//+------------------------------------------------------------------+
int OnInit()
  {
   string string1 = "EURUSD";
   string string2 = "RUON-1.18";
   string string3 = "XXX";   
   string brokerGroupName1=symbolType(string1);
   Print("This Brokers Group Name for: ",string1,": ",brokerGroupName1);
   string brokerGroupName2=symbolType(string2);
   Print("This Brokers Group Name for: ",string2,": ",brokerGroupName2);
   string brokerGroupName3=symbolType(string3);
   Print("This Brokers Group Name for: ",string3,": ",brokerGroupName3);   
   return(INIT_SUCCEEDED);
  }

OutPut From running OnInit code

StringReplace(path,symbol,"");

It is not right.

ok - whats wrong with it? If you had the code - could have saved me a job and posted it?

StringReplace(path,symbol,NULL);

vacuous statement like its not right is not very helpful?

Do you mean that it needs to be more robust in symbol search in group string?

A clue would be helpful since I dont have all day to guess what you mean

path = StringSubstr(path, 0, StringLen(path) - StringLen(symbol));

Yes - more robust thankyou

//+------------------------------------------------------------------+
//|Get the Brokers Group Name for the Symbol                         |
//+------------------------------------------------------------------+        
string symbolType(string symbol)
  {
   string outVal=NULL, path=NULL;
   ResetLastError();//zero last error
   SymbolInfoString(symbol,SYMBOL_PATH,outVal);
   if(!GetLastError())
      return StringSubstr(SymbolInfoString(symbol,SYMBOL_PATH),0,StringLen(SymbolInfoString(symbol,SYMBOL_PATH))-(StringLen(symbol)+1));      
   else
      Alert("Cannot Find: ",symbol," Path");
   return path;
  }
//+------------------------------------------------------------------+
string symbolType(string symbol)
  {
   string path = NULL;
   if (SymbolInfoString(symbol,SYMBOL_PATH,path))
      return StringSubstr(path,0,StringLen(path)-(StringLen(symbol)+1));      
   else
      Alert("Cannot Find: ",symbol," Path");
   return path;
  }

yes agree. Your function is much cleaner and probably faster? I

think the reason I used

GetLastError()

was reading this: https://docs.mql4.com/marketinformation/symbolinfostring

Return Value

The value of string type. In case of execution failure, information about the error can be obtained using GetLastError() function:

4106 — symbol is not selected in "Market Watch" (not found in the list of available ones),
4051 — invalid identifier of a symbol property,
4024 — internal error.

Does a call to GetLastError() add anything iif we alert for the error:

Alert("Error: ",GetLastError());

I dont wish to protract this discussion but I think rewritten with GetLastError would add something.

Anyhow, thanks for your input here. I learned something from you.