Assigning values to an array

 

I am trying (what I belive) something ralatively simple.

Looping back i bars getting the close price of each bar. Putting the close price of the particular bar

to an array and then accessing it returns 0.

What am I doing wrong? I guess it's syntax, but I don't know what..... see code below:

Thanks you for you help

jp

---------------------

double malluege[];
int i=25;
int j=0;

////////////
int init()
{

return(0);
}
/////////

int start()
{

for (j=0; j<i;j++)
{
Print(" Last tick ",iClose(NULL,0,0)); // just for info the last tick information

malluege[j]=iClose(NULL,0,j+1); //// putting close of bar j+1 to array malluege at position j

Print(" j=", j," ",malluege[j]); /// j is returned correctly but malluege[j] is zero
}

return(0);
}

 

malluege is still uninitialized when you try to assign values to it.

double malluege[]= {};

// declaration and initialization. But this thing is still empty, mql4 thinks this is a 0 floor building. Instead of ={} you can use ArrayInitialize(malluege); at any point in the code (before the for loop).

inside the for(j = 0;...) loop add:

ArrayResize(malluege,ArraySize(malluege)+1); // before the malluege[j] = ...

This will "add floors" to your "building" of an array so you can add values to them.

Cheers.

 

thank you very much!!!

As i is maximum to loop I put:

int init()
{
ArrayResize(malluege,i);
return(0);
}


that way I have an i sized one dimensional array that does the trick.

:-)