How do you sort doubles? in an array? Why doesn't this work?

 

If you had 3 moving averages on the chart, and you wanted to get those values added to a double array and sort them, why does this not seem to work?:


double mn1=iMA(Symbol(),43200,120,0,3,6,0);

double mnArray[1]={mn1};


Metaeditor gives an error upon compiling

'mn1' - unexpected token

'mn1' - translator error--out of memory


 
Subgenius :

If you had 3 moving averages on the chart, and you wanted to get those values added to a double array and sort them, why does this not seem to work?:


double mn1=iMA(Symbol(),43200,120,0,3,6,0);

double mnArray[1]={mn1};


Metaeditor gives an error upon compiling

'mn1' - unexpected token

'mn1' - translator error--out of memory


try so:

double mn1 = iMA( Symbol(),43200,120,0,3,6,0);

double mnArray[1] = mn1;

 
Boeing747 :

try so:

double mn1 = iMA( Symbol(),43200,120,0,3,6,0);

double mnArray[1] = mn1;


same error! i've tried it already.
 
Subgenius :

same error! i've tried it already.

and so?

//-------------------------------------------------

double mn1Array[100];

int start()

//----

double mn1 = iMA( Symbol(),43200,120,0,3,6,0 );

mn1Array[1] = mn1;

 
Boeing747 :

and so?

//-------------------------------------------------

double mn1Array[100];

int start()

//----

double mn1 = iMA( Symbol(),43200,120,0,3,6,0 );

mn1Array[1] = mn1;


yes,

double mnArray[1];

double mn1=iMA(Symbol(),43200,120,0,3,6,0);

mnArray[1]={mn1};


not,

double mnArray[2];
double mn1=iMA(Symbol(),43200,120,0,3,6,0);
double mn2=iMA(Symbol(),43200,90,0,3,6,0);
mnArray[2]={mn1,mn2};


https://docs.mql4.com/array

the documentation on arrays does not show using doubles

i've searched the web and not found anything.

 
MnArray[2] does not exist. The array is two elements long, MnArray[0] and MNArray[1].
double mnArray[2];
mnArray[2]={mn1,mn2};
This would work if mn1 and mn2 were constants, not variables
double mnArray[2] ={mn1,mn2};
This is fine.
double mnArray[2];
mnArray[0]=mn1;
mnArray[1]=mn2;
As is this.
double mnArray[2];
mnArray[0]=iMA(Symbol(),43200,120,0,3,6,0);
mnArray[1]=iMA(Symbol(),43200, 90,0,3,6,0);
Or combined and simplified
double lengths[] = {120, 90}; // Size defaults to number of initializations.
double mnArray[2];
for(int i=0; i < 2; i++)
  mnArray[i]=iMA(NULL, PERIOD_MN1, lengths[i], 0,3,6,0);
Reason: