Simple Question - Using Built-In Indicators to fill array

 

I am not sure what I am doing wrong with the following code:

I am trying to fill an array with a built in custom, and then call the individual array elements after the array has been filled. What am I doing wrong?

Here is my code:

<code>

for (i=0; i<25; i++)
{
ADX_bull[i] = iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,i);

}
double ADX_bull_current = ADX_bull[0];

</code>

Thanks for any help :)

~Cal

 

i guess this maybe your problem, the code itself looks correct to me and should work even without the following solution, but i suggest you give it a try

bool ArraySetAsSeries( void array[], bool set)
Sets indexing direction of the array. If the set parameter has the TRUE value, the array will be indexed in a reversed order, i.e., the last element has a zero index. The FALSE value sets a standard indexing order. The function returns the previous status.

you should use

ArraySetAsSeries(ADX_bull,true);
 

Meikel...i tried this...

for (i=0; i<25; i++)
{
ArraySetAsSeries(ADX_bull,true);
ADX_bull[i] = (iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,i));

}
double ADX_bull_current = ADX_bull[0];

Now when i comment ADX_bull_current, it sets it equal to 0, which I assume means it is throwing off an error?

 
If I am trying to do this in an expert advisor...would that cause an issue?
 
Calpurnia wrote >>

I am not sure what I am doing wrong with the following code:

I am trying to fill an array with a built in custom, and then call the individual array elements after the array has been filled. What am I doing wrong?

Here is my code:

<code>

for (i=0; i<25; i++)
{
ADX_bull[i] = iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,i);

}
double ADX_bull_current = ADX_bull[0];

</code>

Thanks for any help :)

~Cal

Silly question; but as you don't show it, is your array defined as a double?

whocares

 
yes it is
 
Calpurnia:

Meikel...i tried this...

for (i=0; i<25; i++)
{
ArraySetAsSeries(ADX_bull,true);
ADX_bull[i] = (iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,i));

}
double ADX_bull_current = ADX_bull[0];

Now when i comment ADX_bull_current, it sets it equal to 0, which I assume means it is throwing off an error?

ArraySetAsSeries(ADX_bull,true); not in the loop - before entering the loop

ArraySetAsSeries(ADX_bull,true);
for (i=0; i<25; i++)
{
ADX_bull[i] = (iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,i));
}
 
I did that and still no luck? This is frustrating...why in the world wouldn't this stupid stuff work? I remove the array, set the equation equal to another variable, and it works just fine...why won't it work in an array in an expert advisor? :(
 
Calpurnia:
I did that and still no luck? This is frustrating...why in the world wouldn't this stupid stuff work? I remove the array, set the equation equal to another variable, and it works just fine...why won't it work in an array in an expert advisor? :(

i really dont know.

sometimes the mql4 compiler does strange things.

try to find a workaround.

even in perl or php there are some bugs, this can happen in every language.

good luck

 

I figured it out.

I was under the impression that when you declared an array (ie "double ADX_bull[];"), you didn't have to declare the dimensions of the array. I added the dimensions of the array to the declaration and it now works. Thanks to everyone for their help though!