Download MetaTrader 5
To add comments, please log in or register
Develop applications to order. Make profit using Freelance service!
macpee
287
macpee 2016.03.24 13:43 

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.

Drazen Penic
2405
Drazen Penic 2016.03.24 18:56  

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
287
macpee 2016.03.24 19:36  
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.
whroeder1
13610
whroeder1 2016.03.25 13:13  
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.
macpee
287
macpee 2016.03.30 13:27  
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.
/
To add comments, please log in or register