"|| - condition cannot be a string"

 

Hello!


if(Symbol() == "EURUSD" || "USDCAD")
Alert("...");

leads to the error "|| - condition cannot be a string"

How can I compare the chart to a  list of symbols?

Thanks in advance!

 
APeng:

Hello!


leads to the error "|| - condition cannot be a string"

How can I compare the chart to a  list of symbols?

Thanks in advance!

if(Symbol() == "EURUSD" || Symbol() == "USDCAD" || Symbol() == "GBPUSD" || Symbol() == "USDJPY")
 
phi.nuts:


omg sometimes the solution is so simple! Thank you :)
 
or
static string myList = "EURUSD, USDCAD, GBPUSD, USDJPY";
if (StringFind(Symbol(), myList) >= 0)
or
static string myList[] = { "EURUSD", "USDCAD", "GBPUSD", "USDJPY"};
for (int iList = ArraySize(myList) - 1; iList >= 0; iList--) if (Symbol() == myList[iList]) break;
if (iList) >= 0)
 

APeng, I think I prefer WHRoeder first answer there <edit: combination of WHRoeder first and second answer>, especially if the broker suddenly change the symbol name without telling us, for example they change EURUSD into EURUSDfx or EURUSDm or EURUSDwhatever.

static string myList[] = { "EURUSD", "USDCAD", "GBPUSD", "USDJPY"};

for (int iList = ArraySize(myList) - 1; iList >= 0; iList--) 
     {
     if (StringFind(myList[iList], Symbol()) >= 0) break;
     }

Print ("Symbol is number ", (iList + 1), "in array list." );