Any integer representation for currency pairs?

 

Hello comrades, just as the integer values for OP_BUY, OP_SELL, OP_BUYLIMIT, OP_SELLLIMIT, OP_BUYSTOP and OP_SELLSTOP are 0, 1, 2, 3 and 4, respectively, are there integer values for the traded instruments. That is, integer values for GBPUSD, EURUSD, USDJPY, etc. The idea is to run through the mentioned instruments using their integer values in a loop such as in the following codes:


int extern IntendedInstrumentInteger;    \\ This value input as 11 say.
int i, FirstInstrumentInteger, LastInstrumentInteger;
void start()
{
for (i == FirstInstrumentInteger, i <= LastInstrumentInteger, i++) 
    {
     if (i == IntendedInstrumentInteger) 
         {
          Print ("Execute some codes");
         }
    }
}


If no such integer values exist, what is a good possible way to run through the currency pairs listed on the broker platform while searching for a particular one? Thank you in advance.

 

Use SymbolsTotal() and SymbolName() to loop through the list of the instruments.

Something like this:

bool all_symbols = true;

for(int i = 0; i < SymbolsTotal(all_symbols); i++)
{
  string instrument = SymbolName(i, all_symbols);
  // do something with a symbol name here
}
 
macpee:
 Thank you @drazen64. I have been able to execute   Print("Symbol ",i, "is ", instrument);  using your codes, and hence I can now print all the instruments at a go. I must confess though that MQL4 has not expressed user-friendliness if this is the only way to return all instruments. Nevertheless, my problem has been solved.
 
Do not trade multiple currencies in one EA
  • You can't use any predefined variables, can't use the tester, must poll (not OnTick,) and usually other problems.
  • Code it to trade the chart pair only. Look at the others if you must.
  • Then put it on other charts to trade the other pairs. Done.
 
WHRoeder:
Do not trade multiple currencies in one EA
  • You can't use any predefined variables, can't use the tester, must poll (not OnTick,) and usually other problems.
  • Code it to trade the chart pair only. Look at the others if you must.
  • Then put it on other charts to trade the other pairs. Done.
Thank you for such advice @WHRoeder.
Reason: