Download MetaTrader 5
To add comments, please log in or register
Searching on MQL5.community is performed in all sections. Try it!
satrap
17
satrap 2014.07.21 02:06 

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
969
honest_knave 2014.07.21 02:23  

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

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

whroeder1
13644
whroeder1 2014.07.21 14:55  
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 2014.07.22 09:54  

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
7993
Keith Watford 2014.07.22 11:58  
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 2014.07.22 12:28  
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 2014.07.25 07:43  
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 2014.07.25 10:09  
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
7993
Keith Watford 2014.07.25 10:43  
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
13644
whroeder1 2014.07.26 11:44  
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