Download MetaTrader 5

compiler error in enumeration

To add comments, please log in or register
satrap
17
satrap  

When I compiler following code

---------- code begin ------------

enum ENUM_ORDER_SYMBOL{

EURUSD, S&P500, OILUS

}; 

---------- code end ------------ 

 

there're "comma expected"  error #155

it seems we can't use "&"  and "-" characters in enumeration.

 

how to solve this issue? 

honest_knave
Moderator
2420
honest_knave  

Simple - you need to rename your enum values with something else.

& is reserved, so you can't use it. 

whroeder1
14778
whroeder1  
satrap: it seems we can't use "&"  and "-" characters in enumeration.
Identifiers - MQL4 Documentation states:
Characters allowed to be written in an identifier: figures 0-9, the Latin uppercase and lowercase letters a-z and A-Z, recognized as different characters, the underscore character (_).The first character can not be a digit.
The identifier must not coincide with reserved word.
satrap
17
satrap  

not all of the symbol name are used allowed words.

does it make sense to rename symbol name and restore back when using (S&P500, and etc.)?

i remember in C language can use double words to print reserved character sets.

Keith Watford
Moderator
9641
Keith Watford  
satrap:

not all of the symbol name are used allowed words.

does it make sense to rename symbol name and restore back when using (S&P500, and etc.)?

i remember in C language can use double words to print reserved character sets.


You wouldn't be able to use any of the symbol enums directly in your code because they will be integers and any code using symbols would require a string.

You could use a switch block to assign string values to a variable in init 

qjol
3243
qjol  
GumRai:


You could use a switch block to assign string values to a variable in init 


in addition to GumRai's solution

you can work out to get the symbols name using SymbollName

satrap
17
satrap  
GumRai:


You wouldn't be able to use any of the symbol enums directly in your code because they will be integers and any code using symbols would require a string.

You could use a switch block to assign string values to a variable in init 


Sorry, I don't get your point. Could you explain more detail?

My current design:

all symbols defined in enum selected by user

Use "EnumToString" to get the string of symbol name defined in enum.

 

My point of view is user doesn't need to open any charts evein in MarketWatch to run my EA.

qjol
3243
qjol  
satrap:


My point of view is user doesn't need to open any charts evein in MarketWatch to run my EA.


there is no such thing

without attaching the EA, indicator or script to a chart it can't work

Keith Watford
Moderator
9641
Keith Watford  
satrap:


Sorry, I don't get your point. Could you explain more detail?

My current design:

all symbols defined in enum selected by user

Use "EnumToString" to get the string of symbol name defined in enum.

 

My point of view is user doesn't need to open any charts evein in MarketWatch to run my EA.


You've already discovered that you cannot use S&P500

Therefore you cannot simply use EnumToString as you will have to use something like SP500 as the Enumeration.

"SP500"will not be recognised as a valid symbol

So use a switch block to assign a value to a string variable depending on the Enum selected. 

whroeder1
14778
whroeder1  
GumRai: So use a switch block to assign a value to a string variable depending on the Enum selected. 
As in
string EnumToSymbol(ENUM_ORDER_SYMBOL e){
   switch(e){
   case SP500:  return("S&P500");
   case OILUS:  ...
   default:     return(EnumToString(e)); // EURUSD
}  }
Of course that won't work with brokers using adorned symbols
// Broker's use a variety of nameing patterns: EURUSD, EURUSDm, EURUSDi
// "EURUSD.", "EURUSD..", "EUR.USD", "EUR/USD", "EURUSD.stp", EURUSDct,
// "EURUSD.G", "EURUSD+", EURUSDpro at least.

To add comments, please log in or register