Yes it is an endless loop but that's the idea.
To keep cycling through all the symbols.
The code below fires every 3 seconds.
Here's code snippet (it's all in one method for demo purposes):
void OnTimer() { // Find next symbol long symbolsTotal = SymbolsTotal(false); long count = GlobalVariableGet("testmem"); if(count >= symbolsTotal) { count = 0; } string newSymbol = SymbolName(count, false); SymbolSelect(newSymbol, true); count++; GlobalVariableSet("testmem", count); // Change chart symbol ChartSetSymbolPeriod(0, newSymbol, Period()); // Remove other symbols from Market Watch CArrayString *symbols = new CArrayString(); for(int i = 0; i < SymbolsTotal(true); i++) { string symbol = SymbolName(i, true); // Get name from local market watch symbols.Add(symbol); } int total = symbols.Total(); for(int i = 0; i < total; i++) { string symbolToRemove = symbols.At(i); // Is the symbol not the current chart or about to // be added? if(newSymbol != symbolToRemove) { // Remove from Market Watch SymbolSelect(symbolToRemove, false); } } delete symbols; }
Not sure what you mean by "symbols" but the code above is in a new Expert Advisor with the ExecuteTimer() set to 3 seconds.
Here's the code (this is in an EA):
int OnInit()
{
//--- create timer
EventSetTimer(3);
//---
return(INIT_SUCCEEDED);
}
I've added the full script see attached file "ForumQuestion1.mq5".
Steps to recreate the error:
- Open the attached script in Metaeditor (it's safe) for Metatrader 5
- Open Task Manager in Windows
- Look for "Metatrader 5 Client Terminal" and note the amount of memory
- Run the script and watch the memory column in Task Manager
The memory slowly increases as the script cycles through the symbols.
Hi,
I've added the full script see attached file "ForumQuestion1.mq5".
Steps to recreate the error:
- Open the attached script in Metaeditor (it's safe) for Metatrader 5
- Open Task Manager in Windows
- Look for "Metatrader 5 Client Terminal" and note the amount of memory
- Run the script and watch the memory column in Task Manager
The memory slowly increases as the script cycles through the symbols.
I tried your code and don't have memory issue.
MT5 Build 1325.
Hi Alain,
Thanks for the response.
I'm on the same build. The memory increase is slow. It takes a few minutes. Basically it increases gradually.
See the attached file "Memory increase.docx.png", I've got some screenshots in there showing it build up over time.
I'm on the same build "MT5 Build 1325"
Machine info:
- Windows 8.1 Enterprise
- 64bit OS
- 16Gb RAM
- i7 processor
Thanks
Hi Alain,
Thanks for the response.
I'm on the same build. The memory increase is slow. It takes a few minutes. Basically it increases gradually.
See the attached file "Memory increase.docx.png", I've got some screenshots in there showing it build up over time.
I'm on the same build "MT5 Build 1325"
Machine info:
- Windows 8.1 Enterprise
- 64bit OS
- 16Gb RAM
- i7 processor
Thanks
I am on Windows 10 if that makes any difference.
Your script is running since some minutes before my previous post. Currently the memory usage is lower than when I started it (280 Mb against 300 Mb).
EDIT: I just checked againt and it's now 189 Mb !!! still decreasing :D
EDIT2: Running on Metaquotes Demo-Server.
Thanks for the feedback.
Think I will upgrade to Windows 10 and see if that makes a difference.
I put it on Windows Server 12 R2 and that also pushes the memory up.
Let me monitor this for a while and give feedback on this thread.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I've got an Expert Advisor that has been setup to cycle through symbols and it chews alot of memory.
I've noticed this is when the symbols are loaded into and out of the Market Watch that is slowly creeps up. So it's not the chart cycling through existing items in the Market Watch but more when new symbols are loaded and removed.
It's setup to do the following:
When I remove as much custom code as possible and just use the steps above to cycle a chart through the available symbols I notice the memory usage on my machine keeps increasing.
The CPU stays and a steady rate but the memory shoots right up.
Questions:
(i.e. rather open a new chart with ChartOpen() instead of using the existing chart with ChartSetSymbolPeriod())
(i.e. is this just the way it works)
Thanks much appreciated