Hello,
I am a bit new to mql5. I have some C++ experience and I would like to create a stack which contains MqlRates.
I have checked the documentation and there is the CStack class from Generic Data Collection https://www.mql5.com/en/docs/standardlibrary/generic/cstack
I thought the declaration was simple, very much like this:
However, this throws an error ( " - objects are passed by reference only Stack.mqh" ). I don't exactly understand how to implement this kind of queues and I didn't manage to find any explanation out there. Could you help me make it work?
Thanks!
#include <Generic\Stack.mqh> MqlRates theRates[]; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- double ratesclose[]; int ratesindex[]; datetime ratestime[]; ArrayResize(ratesclose,10); ArrayResize(ratesindex,10); ArrayResize(ratestime,10); ArrayResize(theRates,10); for (int i=0;i<10;i++) { theRates[i].close = 0.00+double(i); theRates[i].time = TimeCurrent()+i; ratesclose[i] = theRates[i].close; ratesindex[i] = i; ratestime[i] = theRates[i].time; } CStack<double> rateStackClose(ratesclose); CStack<int> rateStackIndex(ratesindex); CStack<datetime> rateStackTime(ratestime); //do the rest with the stack } //+--
example only..simply Cstack does not accept MqlRates / struct, but array of data type..you could ZeroMemory the MqlRates structure to free the memory resource when you're done copying the MqlRates stucture members to array according to their data type and organize them back to MqlRates stucture in case you need it later when you're done with the stack, this is just one of the use cases
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am a bit new to mql5. I have some C++ experience and I would like to create a stack which contains MqlRates.
I have checked the documentation and there is the CStack class from Generic Data Collection https://www.mql5.com/en/docs/standardlibrary/generic/cstack
I thought the declaration was simple, very much like this:
However, this throws an error ( " - objects are passed by reference only Stack.mqh" ). I don't exactly understand how to implement this kind of queues and I didn't manage to find any explanation out there. Could you help me make it work?
Thanks!