How can I release Indicator memory (RAM)?

To add comments, please log in or register
Sharon Aharonov
222
Sharon Aharonov  

Hi all,

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:

ArrayFree(array_name)

ArrayResize(array_name,0)

ObjectsDeleteAll(EMPTY,EMPTY) 

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?


Thanks,

Mladen Rakic
139662
Mladen Rakic  
Sharon Aharonov:

Hi all,

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:

ArrayFree(array_name)

ArrayResize(array_name,0)

ObjectsDeleteAll(EMPTY,EMPTY) 

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?


Thanks,

If that is your problem, use circular buffers wherever you can

Sharon Aharonov
222
Sharon Aharonov  
Mladen Rakic:

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? 

And why do you think it will solve the problem? 
Mladen Rakic
139662
Mladen Rakic  
Sharon Aharonov:

Thanks Mladen, do you know where I can find a good example of using it? 

And why do you think it will solve the problem? 

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


MQL5 Cookbook - Creating a ring buffer for fast calculation of indicators in a sliding window
MQL5 Cookbook - Creating a ring buffer for fast calculation of indicators in a sliding window
  • www.mql5.com
Most calculations performed by traders are conducted in a sliding window. This happens due to the very nature of market data which almost always arrive in a continuous stream regardless of whether we deal with prices, bids or trading volumes. Typically, a trader needs to calculate a value for a certain period of time. For example, if we...
Sharon Aharonov
222
Sharon Aharonov  
Mladen Rakic:

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

Sharon Aharonov
222
Sharon Aharonov  
Mladen Rakic:

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


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.

Any solutions?

Marco vd Heijden
Moderator
11763
Marco vd Heijden  

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..

Amir Yacoby
1306
Amir Yacoby  
Decreasing Memory Consumption by Auxiliary Indicators
Decreasing Memory Consumption by Auxiliary Indicators
  • www.mql5.com
Probably, you have already used or created Expert Advisors or indicators that use other auxiliary indicators for their operation. For example, the famous indicator MACD uses two copies of the EMA (Exponential Moving Average) indicator calculating difference between their values: Such a composite indicator is equivalent to several simple ones...
Sharon Aharonov
222
Sharon Aharonov  

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?


Thanks,



Lorentzos Roussos
30584
Lorentzos Roussos  
Sharon Aharonov:

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?


Thanks,

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 

Lorentzos Roussos
30584
Lorentzos Roussos  
(just saw the image) 
You probably initialize arrays in function calls and then dump them .
Init these arrays once on start (since they have a static size) , never free or resize them (only on Deinit).
Use precalculations for live data , and normal calculations on new bars .
(example : MovingAverage 14 , on a new bar calculate the 13 bars sum (upto bar 1) ,and have the 14th bar fluctuate live )
123
To add comments, please log in or register