MQL5 Group Name (Symbol Type)

To add comments, please log in or register
rob
116
rob  

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);
  }
fxsaber
14678
fxsaber  

SYMBOL_PATH

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
To obtain the current market information there are several functions: SymbolInfoInteger(), SymbolInfoDouble() and SymbolInfoString(). The first parameter is the symbol name, the values of the second function parameter can be one of the identifiers of ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE and ENUM_SYMBOL_INFO_STRING. Some symbols...
Alain Verleyen
39054
Alain Verleyen  
pipReaper:

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?

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

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

Path contains: Forex/EURUSD

Simple - many thanks Alain

rob
116
rob  
//+------------------------------------------------------------------+
//|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

fxsaber
14678
fxsaber  
pipReaper:
StringReplace(path,symbol,"");

It is not right.

rob
116
rob  

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

fxsaber
14678
fxsaber  
pipReaper:

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

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

Yes - more robust thankyou

rob
116
rob  
//+------------------------------------------------------------------+
//|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;
  }
//+------------------------------------------------------------------+
fxsaber
14678
fxsaber  
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;
  }
12
To add comments, please log in or register