Dictionary in mql5

 

Hi everyone,

In an EA using Protrader I have a Dictionary type, that I can store key | value where value can be any type, inclusive arrays.

So, I can do something like this:

Dictionary<string, bool[]> positionParcial;

positionParcial = new Dictionary<string, bool[]>();

positionParcial.Add(_ordId, new[] { false, false, false });

positionParcial[_ordId].SetValue(true, 2);

(bool)positionParcial[_ordId].GetValue(0);

How can I do something like that using mql5? I tried using HashMap but unsuccessful.

Thanks




 
Please use the search engine before posting.
 
Sidnei Vladisauskis:

Hi everyone,

In an EA using Protrader I have a Dictionary type, that I can store key | value where value can be any type, inclusive arrays.

So, I can do something like this:

How can I do something like that using mql5? I tried using HashMap but unsuccessful.

Thanks





#include <generic/hashmap.mqh>
#include <generic/arraylist.mqh>

void OnStart()
{
   CHashMap<string, CArrayList<bool>*> dict;
   bool flags[] = {false, false, true, true};
   CArrayList<bool> array_flags(flags);
   dict.Add("flags", &array_flags);
   
   CArrayList<bool> *temp;
   if(dict.TryGetValue("flags", temp)) {
      for(int i=0; i<temp.Count(); i++) {
         bool flag;
         if(temp.TryGetValue(i, flag)) {
            Print(flag);
         }
      }
   }   
}
 
nicholi shen:


thanks

Reason: