Search code examples
mql4

What function would you use to list the symbols?


Is there a way to set a condition that includes a list of currency symbol pairs and be alerted when that condition is met? What function would you use to list the symbols? Thanks in advance. The following code gives you a rough idea of what i'm trying to do.

      for(i=0;i<Bars; i++)
  {
//Want a list of symbols to scan multiple currency pairs for the following condition
    if(Symbol("EURUSD";"AUDCAD";"USDJPY")Close[i+1]>Close[i+2])

   {
   a=a+1;
//This is what I want to happen if condition is met
   Alert(Symbol()+" 1");
   }

Solution

  • You can use SymbolsTotal and SymbolName to get a list of all the symbols in Market Watch. The following code should give you a start (although it will be permanently giving alerts, I think you need to check exactly what you want alerts for) .

    for(int i=0; i<SymbolsTotal(true); i++)
    {
       string currencySymbol=SymbolName(i,true);
       int a=0;
       for(j=0; j<iBars(currencySymbol,0); j++)
       {
          if(iClose(currencySymbol,0,j)>iClose(currencySymbol,0,j+1)) a++;
       {
       if(a>0) Alert(StringConcatenate(currencySymbol,":",IntegerToString(a)));
    }