asuralm:
You can't . . . use ArrayResize() to change the size of the array and ArraySetAsSeries() to change the way elements are added/removed from the array . . .
Hi all :
2. The second question is how to declare a dynamic array in MQL4? I don't mean the array-timeseries.
I mean something equivalent like vector<double> in C++ or ArrayList in C#. The array can accept new element, delete existing element and its size is variable.
asuralm:
1. the first question is how to loop into the indicator efficiently.
1. the first question is how to loop into the indicator efficiently.
For example, I have a fractal indicator and I want to examine its historical value. A simple task is to count how many swing highs and how many swing lows.
2. The second question is how to declare a dynamic array in MQL4? I don't mean the array-timeseries.- Create an extra array and keep a running count.
ExtUpFractalsBuffer[i] = .. // if (ExtUpFractalsBuffer[i] != 0) upFractalCount[i] = upFractalCount[i+1] + 1; // else upFractalCount[i] = upFractalCount[i+1]; upFractalCount[i] = upFractalCount[i+1] + (ExtUpFractalsBuffer[i] != 0); // Equivalent hack
- A CI can have up to 8 buffers automatically sized. They don't all need to be displayed.
#property indicator_buffers 1 // number of displayed buffers int init(){ //---- 2 additional buffers are used for counting. IndicatorBuffers(3); SetIndexBuffer(0,ind_buffer1); SetIndexBuffer(1,ind_buffer2); SetIndexBuffer(2,ind_buffer3);
Once you go beyond needing 8 then you must manage your own. From my codebool ResizeBuffer(double& buffer[], int size){ if (ArrayRange(buffer,0) != size){ // ArrayRange allows 1D or 2D arrays ArraySetAsSeries(buffer, false); // Shift values B[2]=B[1]; B[1]=B[0] if (ArrayResize(buffer, size) <= 0){ DisableTrading( "ArrayResize [2] failed: " + GetLastError() ); return(false); } ArraySetAsSeries(buffer, true); } return(true); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi all :
I am a newbie to the MT4 programming. I have read through most of the MT4 book but I wasn't able to find any way to loop through the indicator array.
I have two questions.
1. the first question is how to loop into the indicator efficiently.
For example, I have a fractal indicator and I want to examine its historical value. A simple task is to count how many swing highs and how many swing lows.
I have a simple solution as:
The ExtUpFractalsBuffer and ExtDownFractalsBuffer are the buffers in the Fractal Indicator.
Obviously, this is not an efficient solution. Is there any better ways to do that?
2. The second question is how to declare a dynamic array in MQL4? I don't mean the array-timeseries.
I mean something equivalent like vector<double> in C++ or ArrayList in C#. The array can accept new element, delete existing element and its size is variable.
Thanks