I guess (just a guess) that strings would not work with switch (just basic types as int, double ... as in C++).
Also, in case it would work, your example has the "break;" missing after the cases.
This code is just as compact and should do what you need.
Also, in case it would work, your example has the "break;" missing after the cases.
This code is just as compact and should do what you need.
if (MyString=="EURUSD") MyFunction1(); else if (MyString=="GBPUSD") MyFunction2(); else if (MyString=="AUDUSD") MyFunction3(); else MyFunction5();
Shimodax,
Thanks for your reply.
Yeah I use multiple IFs for the time being. I know the Delphi's CASE does not work with strings too. However I haven't found any limitations in MQ4 regarding variable types working with SWITCH statement. That's why I wrote my question.
Thanks for your reply.
Yeah I use multiple IFs for the time being. I know the Delphi's CASE does not work with strings too. However I haven't found any limitations in MQ4 regarding variable types working with SWITCH statement. That's why I wrote my question.
string MyString=Symbol();
switch (MyString)
{
case "EURUSD": MyFunction1();
case "EURCHF": MyFunction2();
}
Compilation gives an error "'switch' - different types in switch statement ".
What is the problem? Thanks!
switch (MyString)
{
case "EURUSD": MyFunction1();
case "EURCHF": MyFunction2();
}
Compilation gives an error "'switch' - different types in switch statement ".
What is the problem? Thanks!
Looking in the help section they are using single quotes around strings, you might give that a try...
david
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
switch (MyString)
{
case "EURUSD": MyFunction1();
case "EURCHF": MyFunction2();
}
Compilation gives an error "'switch' - different types in switch statement ".
What is the problem? Thanks!