My indicator runs on every chart that I open, but the problem is that the memory usage (RAM) increase madly.
So I tried to free and delete all general arrays and objects of not in focus charts, using anything:
but nothing really releases the memory
I understand that there is a function IndicatorRelease() that may help but it's not exists on MQL4 (just 5)
Can someone know about a solution?
If that is your problem, use circular buffers wherever you can
Thanks Mladen, do you know where I can find a good example of using it?
Use its other name in search (ring buffer) and some of the useful links will be found on this site :
Also, you can find a (much simpler and much faster I must say) implementation in quite a few of my code published in the code base (look for ringSize keyword in the code - I know that the "purists" are going to dislike it, but ring buffers really need just a couple of things calculated instead of doing the zillion operations enchilada), and if done correctly, then they save memory a lot
But you also must know that there are some limitations for circular - ring - buffers and that some algos simply can not be adapted into circular buffers. Also you must know exactly how they can be used (more or less, forget about random access to calculated data in vast majority of cases). You shall have to find that out in your own code
That much I can tell based on your semi cryptic statement (that "but the problem is that the memory usage (RAM) increase madly.") All the rest is up to you now
Thanks Mladen, I'll check the links and will see if it can help me (hopefully!!).. and will update
Mladen, after I've checked your links I understood what you ment in the ring buffer, but it's not solving my problem, and I'll explain.
The ring buffer that you offered is ment to prevent increasing of arrays (that stores data for calculations etc.) while chart is on the fly and new data arrives and therefore increases the arrays, so the ring buffer removes old data while insert the new, and this method keeps the memory in a fixed size.
The problem in my case is somthing else. All of my arrays are in a fixed size from the beginning, but the problem is that when I open more and more new Charts and my Indicator is attched to them too, the (RAM) memory usage is increased badly (and it's logical of course).
So my idea was to use the functions that I mentioned above, ArrayFree(array_name), ArrayResize(array_name,0), ObjectsDeleteAll(EMPTY,EMPTY) , to free all general arrays and objects, when the Charts is not in a focus (which means that just the focused Chart will realy works when it is on focus and all of the other are stopped)
but nothing of the above functions really releases the usage memory.
Reduce the number of drawn / calculated bars, possible limited to only the visible bars on chart, to limit memory usage.
I usually set it to 250 bars or so and make sure that only the last bar is recalculated on tick so not the whore deal because i get the possibility of that cause from your explanation..
All my bars are calculations are limited, this is not the problem.
When 1 Chart is open with my Indicator it's uses a lot of memory, but it's ok, because it's contains a lot of data in it. It's not a regular Indicator, it's more a trading tool (see attched image)
The problem as I explain is, when I'm opening more and more Charts that runs my Indicator/Tool in it, than the memory usage is very very large.
To prevent it, I tried to free the arrays and delete the objects of all Charts that not currently on focus, but with no success.
The using of the functions ArrayFree(array_name) or ArrayResize(array_name,0) maybe emptied the arrays but there is no effect on the memory usage, and the same with the function ObjectsDeleteAll()
I wrote earlier that I understand that there is a function IndicatorRelease() that may help but it's not exists on MQL4 (just 5).
So is there any other solutions?
You release memory when chart is not in focus so you only need the latest calculated values from all buffers ?ArrayResize is a major bottleneck(er) as well