Array help...

 

Search is down ...and I'm trying to change (Overwrite) elements in array in an EA.

I've tried as many ways as I can think...

I'm setting Lot sizes to an array...and I want to use larger values as the account grows...

I've simplified it here for demonstration

//=======================================

extern double changeover=2000.00;


double lot[4]={0.1,0.2,0.3,0.4};


if (AccountBalance()>changeover)

{

lot[4]={0.2,0.4,0.8,0.9};

}

//=========================================

I've also tried creating two arrays and copying the "bigger" lot array into the real lot array....

//==========================================


extern double changeover=2000.00;

double biglot[4]={0.2,0.4,0.8,0.9}

double lot[4]={0.1,0.2,0.3,0.4};


if (AccountBalance()>changeover)

{

ArrayCopy(biglot,lot,0,4);

}


//=======================================================


I've also tried every possible command in place of the

ArrayCopy(biglot,lot,0,4)

ArrayCopy(biglot,lot,0,0)

ArrayCopy(biglot,lot)

ArrayCopySeries(biglot,lot,0,4)

etc etc etc....

}

//=======================================================

Can anyone help me?

Again sorry but search is down....

Thanks...

 

Hi

You can only use the syntax "double lot[4]={0.1,0.2,0.3,0.4};" for initialising an array. After that lot[4] refers to the element with index 4, which is greater than the highest element. I think this should produce a complier error, but it doesn't.

I think you will have to assign each element separately. E.g.

lot[0] = 0.2;

lot[1] = 0.4;

lot[2] = 0.8;

lot[3] = 0.9;

Cheers

Jellybean

 

Jellybean...Thanks...worked great!!

What was wrong with the ArrayCopy code??

 
n8937g:

Jellybean...Thanks...worked great!!

What was wrong with the ArrayCopy code??


Glad it helped.

In your ArrayCopy solution you have the source and destination arrays the wrong way around. You are copying from lot to biglot.

ArrayCopy( lot, biglot ); works fine.

See https://docs.mql4.com/array/ArrayCopy

Cheers

Jellybean