Discussion of article "MQL5 Cookbook: Implementing an Associative Array or a Dictionary for Quick Data Access" - page 3
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
I decided to use this class in my EA as a container of strategies of the form (StrategyGUID, Strategy), where StrategyGUID is an identifier of ulong type; Strategy is a strategy created on the basis of a class with inheritance from CObject.
Accordingly, I declare the necessary variables, including CDictionary StrategyBook - the book of active strategies; I create the necessary strategies Strategy01, Strategy02, which in the OnInit() function of the EA initiate various parameters, including assigning them unique GUIDs. At the very end of OnInit() I decide to save the strategies in StrategyBook by calling the code
StrategyBook.AddObject(Strategy01.strGUID,Strategy01);
StrategyBook.AddObject(Strategy02.strGUID,Strategy02);
And then I get the error "StrategyXX - parameter conversion not allowed" on both lines.
Based on my experience with C#, everything is done correctly. But in MQL5 I get this error.
What can it be related to?
I decided to use this class in my EA as a container of strategies of the form (StrategyGUID, Strategy), where StrategyGUID is an identifier of ulong type; Strategy is a strategy created on the basis of a class with inheritance from CObject.
Accordingly, I declare the necessary variables, including CDictionary StrategyBook - the book of active strategies; I create the necessary strategies Strategy01, Strategy02, which in the OnInit() function of the EA initiate various parameters, including assigning them unique GUIDs. At the very end of OnInit() I decide to save the strategies in StrategyBook by calling the code
StrategyBook.AddObject(Strategy01.strGUID,Strategy01);
StrategyBook.AddObject(Strategy02.strGUID,Strategy02);
And then I get the error "StrategyXX - parameter conversion not allowed" on both lines.
Based on my experience with C#, everything is done correctly. But in MQL5 I get this error.
What can it be related to?
There can be several reasons. Most likely, either type incompatibility or incorrect work with pointers. Also, we cannot exclude the peculiarities of working with template methods (they also have their own nuances).
In general, it is better to use a ready-made trading engine, you will save a lot of time and nerves: https://www.mql5.com/en/articles/2166.
Yeah, that's what I eventually decided to do.
New article MQL5 Cookbook: Implementing an Associative Array or a Dictionary for Quick Data Access has been published:
Author: Vasiliy Sokolov
Thanks for all the effort, but I cannot seem to get any of the code examples working.
It seems Dictionary dict; should be CDictionary dict;
How about a simple working example?
Regarding new MT4 (Build 1080, 12 May 2017) these errors occur while compiling and prevents execution:
'm_array' - structures containing objects are not allowed Dictionary.mqh 303 25
Hello,
As previously said by another person, there is no compilable example.
Only a file with comments in Russian.
I'm gratefully using Vasiliy's library successfully. It's a real help!
I remember I had some compiler errors too and could fix them. However, I can't really say which they were and what I did.
And bc I'm extremely annoyed by the formatting of MQL5 code & I always reformat everything to a modern C++ format (proper indenting, avoiding unnecessary brackets, no comment clutter, and so on), it's impossible for me to say what was the real change in code. All I remember is, that the changes were small.
In case you want to use the proper formatted library, here it is:
(Note, that I am using tabs, so the formatting looks broken here, but in the MetaEditor it isn't!)
I think I found a bug when deleting an element and trying to get to the last element:
Error in the CDictionary.mqh will be:
invalid pointer access in 'Dictionary.mqh' (463,9)
Can anyone confirm this? Any ideas how to fix?