- You can research hashing.
- Or just use the symbol as part of your named Global Variable. Done.
- You can research hashing.
- Or just use the symbol as part of your named
Global Variable. Done.
Thank you for the named Global variable suggestion. That's flipping the problem around and giving a solution. Cheers!
(its prone to errors careful)(was bored and built this,but use Williams suggestion)
int OnInit() { //--- ki Test; Test.SetDictionary("(A,11)(B,12)(C,13)(D,14)(E,15)(F,16)(G,17)(H,18)(I,19)(J,21)(K,22)(L,23)(M,24)(N,25)(O,26)(P,27)(Q,28)(R,29)(S,31)(T,32)(U,33)(V,34)(W,35)(X,36)(Y,37)(Z,38)(0,39)(1,41)(2,42)(3,43)(4,44)(5,45)(6,46)(7,47)(8,48)(9,49)(_,51)(-,52)(.,53)"); Test.SetSeparator(0,false); ki_value coded=Test.FindCode("EURUSD"); Alert("result : "+coded.String); string back_to_text=Test.FindTextFromCode(coded.String); Alert("back to text : "+back_to_text); //--- return(INIT_SUCCEEDED); } struct ki_value { string String; ulong ULong; ki_value(void){String=NULL;ULong=NULL;} }; class ki { private : ki_value Separator; ki_value Dictionary[]; public : bool UseSeparator; ki(void){Clear();} ~ki(void){Clear();} string FindTextFromCode(string code) { string result=""; if(StringLen(code)==0){Alert("code is empty");} if(ArraySize(Dictionary)==0){Alert("No Dictionary");} if(ArraySize(Dictionary)>0&&StringLen(code)>0) { //with separator if(UseSeparator) { ushort us=StringGetCharacter(Separator.String,0); string results[]; int k=StringSplit(code,us,results); if(k>0) { for(int i=0;i<k;i++) { ulong cod=(ulong)StringToInteger(results[i]); for(int d=0;d<ArraySize(Dictionary);d++) { if(cod==Dictionary[d].ULong) { result+=Dictionary[d].String; break; } } } } ArrayFree(results); } //with separator ends here //without separator if(!UseSeparator) { int codes_size=2;// int len=StringLen(code); for(int c=0;c<len;c+=codes_size) { string extr=StringSubstr(code,c,codes_size); ulong cod=(ulong)StringToInteger(extr); for(int d=0;d<ArraySize(Dictionary);d++) { if(cod==Dictionary[d].ULong) { result+=Dictionary[d].String; break; } } } } //without separator ends here } return(result); } ki_value FindCode(string text) { ki_value result; if(StringLen(text)==0){Alert("Text Is Empty!");} if(ArraySize(Dictionary)==0){Alert("No Dictionary");} if(ArraySize(Dictionary)>0&&StringLen(text)>0) { result.String=""; int chars=StringLen(text); for(int c=0;c<chars;c++) { string character=StringSubstr(text,c,1); for(int d=0;d<ArraySize(Dictionary);d++) { if(character==Dictionary[d].String) { result.String+=IntegerToString(Dictionary[d].ULong); if(c!=chars-1&&UseSeparator) result.String+=IntegerToString(Separator.ULong); break; } } } result.ULong=StringToInteger(result.String); } return(result); } void SetSeparator(ulong separator_value,bool use_separator){Separator.String=IntegerToString(separator_value);Separator.ULong=separator_value;UseSeparator=use_separator;} void SetDictionary(string comma_separated_list_of_characters_used_and_their_counterparts) { Clear(); ushort us_open_paren=StringGetCharacter("(",0); ushort us_close_paren=StringGetCharacter(")",0); ushort us_comma=StringGetCharacter(",",0); string result[],resultb[]; //A.Split into parentheses int k=StringSplit(comma_separated_list_of_characters_used_and_their_counterparts,us_close_paren,result)-1;//-1 cause last parenthesis splits with void if(k>0) { ArrayResize(Dictionary,k,0); //loop into parenthesized elements for(int p=0;p<k;p++) { //remove open parenthesis int rep=StringReplace(result[p],"(",""); //split values ,first value is string ,second value is ulong int m=StringSplit(result[p],us_comma,resultb); if(m==2) { Dictionary[p].String=resultb[0]; Dictionary[p].ULong=(long)StringToInteger(resultb[1]); } } //loop into parenthesized :D elements ends here } ArrayFree(result); ArrayFree(resultb); } private : void Clear(){ArrayFree(Dictionary);Separator.String="0";Separator.ULong=0;UseSeparator=true;} };
Hello,
I want to take the value of the current _Symbol and convert it to a numeric representation that can be stored as a double in a named global variable. So, a kind of 1-way encryption process that outputs as a double? Is there a way to do this in MQL4?
Thanks.
I've always used the index value from the Symbol list for that type of thing? Wrong?
string sym=_Symbol; double symid=-1; for(int i=0;i<SymbolsTotal(true);i++) if(SymbolName(i,true)==sym){ symid=(double)i;break;} Print(sym," : ",symid);
I've always used the index value from the Symbol list for that type of thing? Wrong?
(its prone to errors careful)(was bored and built this,but use Williams suggestion)
What is the purpose of this code, I don't get it ? Of course I see what it does, by why would you need it ?
![](https://c.mql5.com/3/308/name_to_something.png)
I dont know 1123111925 ,i started with the thread in mind and then it became this ,-while having the first coffee for the day- :D
I dont know 1123111925 ,i started with the thread in mind and then it became this ,-while having the first coffee for the day- :D
My question was related to symbol's name. Anyway...you will find a usage next year :-D
(its prone to errors careful)(was bored and built this,but use Williams suggestion)
Wow, amazing effort for just being "bored"! Thank you very much for going to so much trouble - I appreciate it :)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I want to take the value of the current _Symbol and convert it to a numeric representation that can be stored as a double in a named global variable. So, a kind of 1-way encryption process that outputs as a double? Is there a way to do this in MQL4?
Thanks.