Array question by newbie

 

How do i store the the current value of a variable in array element location 0 and the previous bar's value of the same variable in element location 1 of the array?

thks.

 

double var=new_val;

if(var!=arr[0])

{

arr[1]=arr[0];

arr[0]=var;

}

 
Roger wrote >>

double var=new_val;

if(var!=arr[0])

{

arr[1]=arr[0];

arr[0]=var;

}

thks a lot! i'm still rusty and just beginning w mql4.

 
jessica wrote >>

thks a lot! i'm still rusty and just beginning w mql4.

Me to!

I was hoping for LOTS of detailed and informative feedback on Arrays.

 
FourX:

Me to!

I was hoping for LOTS of detailed and informative feedback on Arrays.

Ask specific questions... Or u can read about it -> https://book.mql4.com/variables/arrays.

 
arr[1]=arr[0];
arr[0]=var;
However, if you're writing an Indicator, then the arrays automatically adjust themselves
double TempBuffer[];
int init() {
	IndicatorBuffers(6);
	SetIndexBuffer(5,TempBuffer);
//...
Reason: