Jose Luis Lominchar:
ENUM_OPS eVal = BUY;
Is there a way to cast or convert from a string to an ENUM.
This is a simplification of the problem:
Which is the proper way to assign sVal to eVal?
Thanks!
//+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- string sVal = "BUY"; ENUM_OPS eVal; Print(EnumToString(eVal=StringToEnum(sVal,eVal))); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_OPS { BUY = 1, SELL = 2 }; template<typename T> T StringToEnum(string str,T enu) { for(int i=0;i<256;i++) if(EnumToString(enu=(T)i)==str) return(enu); //--- return(-1); } //+------------------------------------------------------------------+
Ernst Van Der Merwe:
Thank you very much, it works !
Jose Luis Lominchar:
Thank you very much, it works !
You're welcome.
Ernst Van Der Merwe:
I had the same issue, your solution helped me too. Thank you.

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
Is there a way to cast or convert from a string to an ENUM.
This is a simplification of the problem:
Which is the proper way to assign sVal to eVal?
Thanks!