Storing number of opened trades in static variable like dictionary

 
Hello guys,
im facing issue with BasicHashLoop in  "hastable-templated.mqh" which I am using for having avalable something like dictionary is in different languages.

Ofcourse I would like to not use third party codes, but Im not sure how to solve the situations that I need to hold number(count) of trades for each MagicNumber in graph (magicNumbers are being dynamicly changed as new sequencies of trades are being created - so I can not use standard static variables like magic_number1=X magic_number2=Y because I dont know how many will be opened at same time)

So Im now using dictionary as I have described above - dictionary[magicNumber]=numberOfTrades. This needs to be static dictionary because of in OnTick() im calculating how many trades is opened now, and if this number is bigger than the one in dictionary, it means new trade has been triggered (pending -> market)

1) Does anyone know how to solve this without using third party dictionaries?


Problem with this third party dictionary is that sometimes I get "invalid pointer access in hashtable-templated.mqh", and whole EA just crashes and let trades opened. I know it is probably because Im trying to remove some key from dictionary which is not in there, but... I would like to let this dependency disappear.

Thank you for your time and your words.
Have a wonderful day.
Sincerely Foed
 
Anyone dont know how to store values in something that would work as dictionary? :/
 

How many different sequences do you expect to have running at one time?

D‌o you need historical access, or just the live ones?

 
honest_knave:

How many different sequences do you expect to have running at one time?

D‌o you need historical access, or just the live ones?

‌Thank you for you answer.

Total sequencies during time could be abot 100.000. Can not exactly tel how many sequencies could be opened at the same time. In most of the time it will be one or two. but can be about 10 or 20. This is exactly the problem where dictionary is the best solution... Unfortunately :(

 
Foed:

Problem with this third party dictionary is that sometimes I get "invalid pointer access in hashtable-templated.mqh", and whole EA just crashes and let trades opened. I know it is probably because Im trying to remove some key from dictionary which is not in there, but... I would like to let this dependency disappear.

If the map meets your needs in all aspects except for this specific error, why don't you fix it? The error message should provide you a line number where it happens.
 
Stanislav Korotky:
If the map meets your needs in all aspects except for this specific error, why don't you fix it? The error message should provide you a line number where it happens.

Im trying for more than 3 days and can not solve it. That pointer thing happens in thirdparty code which is kinda complicated.



The code ,after about 70 trades ,suddenly  throws error "invalid pointer access in 'hashtable-templated.mqh' (967,24)" and EA crash.
I have found out it happens when I am calling ContansKey() function.
'Im using BasicHashTable<int,int>. The only methods I am using is Get for getting value, Set for creating value in dictionary and remove for deleting specific entry in dictionary.

Before calling ContainsKey() I tried to print all values from dictionary and it gets 6 values, but when I call method getCount() it return number 11!. I  think this is the problem.

I can not get know why I am getting 11 values after calling getCount().


My code works like this (simplified, but inportant parts and variables are there - whole code has about 1,5k rows):

onTick()
{
    static BasicHashTable<int,int> dict_magic_trades;
    if(OrdersTotal()==0) // delete everything from dictionary
    {
        BasicHashLoop<int,int> *l ;
        if(dict_magic_trades.ContainsKey(l.val())
         {
            dict_magic_trades.Remove(l.val());
         }
         delete l;
    }
    else
    {
        int MagicNumber=get_function_for_MR();
        Print("count:" +dict_magic_trades.getCount());   //returns 11
        BasicHashLoop<int,int> *l ;
        
        // this prints 6 values out of dictionary
        for( l = new BasicHashLoop<int,int>(&dict_magic_trades) ; l.hasNext() ; l.next())
            {
                
                 int key = l.key();
                 int val= l.val();
                 Print("HASH_INSIDE["+key+"]="+val);
            }
        if(dict_magic_trades.ContainsKey(MagicNumber)   // here it crashes .. after about 70 trades..
              {
                ....
              }
    }


   
Thank you for help if you can find something what it can cause.

Have a nice day and lot of pips .)




 

@Foed

Which build are you using?

T‌here were handle issues with Build 1045, and given the handle/pointer distinction in MQL...

 
Foed:

Im trying for more than 3 days and can not solve it. That pointer thing happens in thirdparty code which is kinda complicated.



The code ,after about 70 trades ,suddenly  throws error "invalid pointer access in 'hashtable-templated.mqh' (967,24)" and EA crash.
I have found out it happens when I am calling ContansKey() function.
'Im using BasicHashTable<int,int>. The only methods I am using is Get for getting value, Set for creating value in dictionary and remove for deleting specific entry in dictionary.

Before calling ContainsKey() I tried to print all values from dictionary and it gets 6 values, but when I call method getCount() it return number 11!. I  think this is the problem.

I can not get know why I am getting 11 values after calling getCount().


My code works like this (simplified, but inportant parts and variables are there - whole code has about 1,5k rows):


You provided your code, whereas the error is indicated as happening on a specific line inside the mqh-file. In other words, you show irrelevant code. Moreover, to understand the map logic the full header source code may be required.

A‌FAICU, the header file is a 3-rd party file. So it's not clear why you can't use a different 3-rd party implementation of a map, if you think that currently selected implementation is buggy.

 
Stanislav Korotky:


You provided your code, whereas the error is indicated as happening on a specific line inside the mqh-file. In other words, you show irrelevant code. Moreover, to understand the map logic the full header source code may be required.

A‌FAICU, the header file is a 3-rd party file. So it's not clear why you can't use a different 3-rd party implementation of a map, if you think that currently selected implementation is buggy.

I can not find the another one implementation of dictionary for mql4. Do you , please, know any?
.mqh file is now attached, but I thought there could be some my mistake in my usage.
Files:
 

Forum on trading, automated trading systems and testing trading strategies

Help please, array mangement question. MQL4 vs .Net

JC, 2017.02.18 10:29

My personal favourite is https://www.mql5.com/en/code/11117

The attached version updates it to use the templates which became available in MQL4 after the original code was written. 


 
Alain Verleyen:


Yes, thats exactly the one I am using. 
Reason: