The Magic No. is now of type ulong so from 0 bis 18 446 744 073 709 551 615.
You can use different parts of the long number (19 digits) to store different information, like the last 3 digits for information you often use (=>magic%1000=615 from above). It can be stored in one function which can be included in any EA for any purpose.
Even more unconventional would be to cast ulong (8 bytes) into the type datetime (also 8 bytes), then one would have this value structured in:
- Years 1970-3000
- Months 1-12
- Days: 1-28 (29-31 are sometimes, sometimes not)
- Hours 0-23
- Minute 0-59
- Seconds 0-59
This way you have 6 different sections of the 20 digits and in total 29 901 312 000 options to store information - enough I guess.
Of course it's no the way datetime was meant but it should work.
Dominik Christian Egert #:
As far as I am aware, SQLite supports already thread safety. That's why you are getting the error message. You will need to read about locking tables and transactions.
Yeah, I really lost myself in that one ^.^ Actually what I need is a Qt's function where until the thread-safe code is released, the code is blocked, something like "waitUntilReleased" function.
Ok! I'll read about that unknown function.
Well, my plan is to have a considerable number of EAs running different strategies in different symbols, 50 or more. And I need to be organized relative to which EA is running which strategy in which symbol in which broker in which Terminal in which computer... For that, I keep an Excel table where the Magic Number is the ID of the EA. And with that many EAs, what may happen is that I may mistakenly eventually load the same preset file twice, an error I'ld like to avoid.
I used GV a little bit some time ago, but it felt a little okward :| Specially because when the whole system gets ready (50 EAs or more), that may produce an ugly list of Global Variables put together with other global variables... That looks messy.
Well, my plan is to have a considerable number of EAs running different strategies in different symbols, 50 or more. And I need to be organized relative to which EA is running which strategy in which symbol in which broker in which Terminal in which computer... For that, I keep an Excel table where the Magic Number is the ID of the EA. And with that many EAs, what may happen is that I may mistakenly eventually load the same preset file twice, an error I'ld like to avoid.
Can't you have the magic number formated in such a way that you can calculate it on the fly like Carl Schreiber said?
For example, the first 8 bits to store the symbol ID, the next 8 bits to store the strategy ID, the next 8 to store the broker ID, etc...
Since the magic number is a 64 bit, you could encode a lot of information there and your use case looks simple enough.
Can't you have the magic number formated in such a way that you can calculate it on the fly like Carl Schreiber said?
For example, the first 8 bits to store the symbol ID, the next 8 bits to store the strategy ID, the next 8 to store the broker ID, etc...
Since the magic number is a 64 bit, you could encode a lot of information there and your use case looks simple enough.
Well, that's possible... And maybe it wouldn't cost too many extra input variables. I'll think about it :)
EDIT: I thought and think it wouldn' suit me. Ultimately I'll still need a numeric ID for the strategies and some security mechanism I'm not repeating strategy/preset files, which is what Magic Numbers are doing for me right now.Well, that's possible... And maybe it wouldn't cost too many extra input variables. I'll think about it :)
EDIT: I thought and think it wouldn' suit me. Ultimately I'll still need a numeric ID for the strategies and some security mechanism I'm not repeating strategy/preset files, which is what Magic Numbers are doing for me right now.For example, you have a global boolean indicating if it was initialized or not, and, during OnTick/OnTimer, try to initialize
the EA (calling the SQLite database) if it is false, this way it'll keep retrying until it get the settings it need from the database
and SQLite will make sure only one of them will have access at a time as it will give you an error if some other EA is accessing it.
I see, an alternative is to NOT try to initialize the EA on the OnInit function but on the OnTick or OnTimer.
For example, you have a global boolean indicating if it was initialized or not, and, during OnTick/OnTimer, try to initialize
the EA (calling the SQLite database) if it is false, this way it'll keep retrying until it get the settings it need from the database
and SQLite will make sure only one of them will have access at a time as it will give you an error if some other EA is accessing it.
Thanks for the idea, Alexandre!
I never though about initializing the EA in OnTick/OnTimer; that seems so unorthodox. That being sad, I'm not sure if that approach would be better then the one I have now, which is: still using SQLite database to check if a certain MN has been used, if it tries to read/write the table and is locked by another EA being initialized, it just try again inside a "for" loop. After all, this process is fast and normally in the second attempt the table has already been released.
Thank Dominik for your replies!
I'm under the impression having a single SQLite database to manage the MN is far more 'elegant' than having a pile of files with 0 or 1 byte and other alternatives. Regarding the CRC-64 idea, I'm not sure it would work in case I open two EAs in the same asset and period in the same terminal with the same presets; whatever checking mechanism would still accept the second configuration and I'll end up with two identical EAs!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi!
In order to avoid two or more EAs to end up having the same Magic Number, I developed a global SQLite database using MQL5s own "DatabaseFunctions" where any EA, upon OnInit, registers its own MagicNumber if it is not already in use and erases its record on OnDeinit.
The problem is that different graphs work in different threads and so what is happening is that whever I load two or more EAs, there is an write or read error with 5605 "database error, database is locked". I guess this implies I need to make the access to my database be "thread-safe".
Well is there something more "native" in the Database system which would allow me to avoid having to use mutexes/semaphores or the GlobalVariables? I couldn't find anything. And if the answer is "no", has MetaQuotes already implemented some native mutex/semaphore or do I still need to use some 3rd party library?