This forum is in read-only mode now. You may discuss your questions on forums of MQL4.community and MQL5.community

iMAonarray problem in an expert advisor


Back to topics list  | 1 2
avatar
350
phy 2007.11.05 06:42 
Why are you setting FALSE?

Here is a test indicator.
There are two data arrays. One is set as a series, the other, not.
Both data arrays are filled with the same data. The values are bar closing price.
Then, iMAOnArray is taken on each data array
The result is a 10 period moving average of closing price



#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
double arraySeries[];
double arrayNot[];
int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,arrayNot);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,arraySeries);
   SetIndexDrawBegin(0, Bars - 490);
   SetIndexDrawBegin(1, Bars - 490);
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
	int i;	
	double dataNot[501];
	double dataSeries[501];	
	ArraySetAsSeries(dataNot, false);
	ArraySetAsSeries(dataSeries, true);

	for(i = 500; i >=0 ; i--){
		dataNot[i] = Close[i];
		dataSeries[i] = Close[i];
	}
	
	for(i = 490; i >= 0; i--){
		arrayNot[i] = iMAOnArray(dataNot, 0, 10, 0, 0, i); // red
	}

	for(i = 490; i >= 0; i--){
		arraySeries[i] = iMAOnArray(dataSeries, 0, 10, 0, 0, i); // green
	}
   return(0);
  }









avatar
11
47steps 2007.11.05 16:29 
I thought FALSE must be used when xxxonArray is used in an EA. Is this correct? Or can TRUE also be used? The order of elements must be important?

Thank you.
avatar
350
phy 2007.11.05 16:48 
Examine the test above and decide.

Note which method in the test gives a valid moving average line, and how it is acheived.

avatar
11
47steps 2007.11.06 04:24 
Only a value of True with ArraySetAsSeries gives the correct values. A value of False does not work in an EA.

Thanks
avatar
350
phy 2007.11.06 04:44 
Using "normal" array fill methods, yes. If you put bar0 data into array0, bar1 into array1, etc, then use ArraySetAsSeries on the array before using the built in iXxxOnArray function.
avatar
11
47steps 2007.11.09 06:02 
Forgive me for taking up so much of your time with this. Thanks for all your help, but I'm afraid I have a second question.

Is it possible to have an array within an array? In other words, let us say that we have put RSI data in an array. We want to run an MA on this RSIarray. But then we want to store this data in a second array, MAofRSIarray, and run a further function, such as Momentum, on this MAofRSIarray. In the end, we will then have MomentumofMAofRSIArray. Obviously we need to use iMAonArray and iMomentumonarray in combination.

Can this be done, and if so, how?

47steps
avatar
350
phy 2007.11.09 06:33 
you can have multidimensional arrays

array[5][11][7] for example, 3 dimensios..

5 elements, 11 wide, each of which is somehow 7 deep

"Arrays are allowed to be maximum four-dimensional. Each dimension is indexed from 0 to dimension size-1."
avatar
11
47steps 2007.11.09 06:52 
Thanks for the quick reply. If I understand correctly, a multidimensional array is just a collection of data that can be from different sources. However, here we want to create an array, run xxxonarray on that array, store the new data in an array, and then run yyyonarray on this new array. I don't see how a multidimensional array applies here. Or did I miss something?
avatar
350
phy 2007.11.09 08:05 

Don't know what you're trying to do.

avatar
2
WHR 2010.04.14 19:10 
  1. The asSeries only effects element indexing A[i]. Build the array with asSeries(true) right most index is A[0]
  2. The xxxonArray Always goes left to right. right most value should be newest
  3. Article: Effective usage of Arrays in MQL
Back to topics list   | 1 2  
Download MetaTrader 5 (450 Kb, web installer) — a new terminal for financial markets