interpret the following problem which is related to weighted moving average

 

Hi can anyone help me interpret the following problem  


the idea that I am trying to apply is finding heights between close prices and Weighted moving average. 

int max_height;  // to be used next
double up_height[50]; // to be used next
double down_height[50]; // to be used next



double close [50] ; 
double WMA [50] ;
double height [50] ;

ArrayInitialize (close , EMPTY_VALUE); 
ArrayInitialize (WMA , EMPTY_VALUE);
ArrayInitialize (height , EMPTY_VALUE);



ArrayInitialize (up_height , EMPTY_VALUE); // to be used next
ArrayInitialize (down_height , EMPTY_VALUE);  // to be used next



for(int i=0; i<=49 ; i++){
WMA[i] = iMA(Symbol(), PERIOD_M1, 3, 0,MODE_LWMA, PRICE_CLOSE, i);
close [i] = iClose(Symbol(),PERIOD_M1,i);
}

for(int n = 0; n < 49; n++)
        {
                height[n] = close[n] - WMA[n]; // here we found heights array every thing is cool ,, 
                
        }

 

then I wanted to sort the values by using  arraysort function https://docs.mql4.com/array/arraysort , in the following code : 

.
.
.
.
ArrayCopy(up_height,hight,0,1,WHOLE_ARRAY);
ArrayCopy(height,down_hight,0,1,WHOLE_ARRAY);
ArraySort(up_height,WHOLE_ARRAY,0,MODE_ASCEND);
ArraySort(down_height,WHOLE_ARRAY,0,MODE_DESCEND);

.
.
.
Comment((string)down_height[0] +"...."+ (string)down_height[1] +"...."+(string)down_height[2] +"...."+(string)down_height[3] +"...."+(string)down_height[4] );


the results with the up-height sorting (the ascending) was good .. no problem 

but the down_height gives me very huge number which does not exist at all in millions .. where the close price has only moved few pips above the weighted moving average 


probably (>50%)  there is something wrong with the code . 


but when I used ArrayMaximum function 

max_hight= ArrayMaximum(hight,WHOLE_ARRAY,0)

the same number appeared ... I see that the mql4 reads this number to be the largest height from the past 50 steps 

 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
ArrayCopy(up_height,hight,0,1,WHOLE_ARRAY);
ArrayCopy(height,down_hight,0,1,WHOLE_ARRAY);

You copied [1 … 49] values to [0 … 48]. Why does it surprise you that element 49 is still EMPTY_VALUE?

 
William Roeder:

You copied [1 … 49] values to [0 … 48]. Why does it surprise you that element 49 is still EMPTY_VALUE?

still the same problem .. 

Reason: