Average of CopyHigh and CopyLow

 

I use this to get an array of the highest bar prices:

         copyed = CopyHigh(NULL,0, 0 ,5,clpr);

I use this to get an array of the lowest bar prices:

         copyed = CopyLow(NULL,0, 0 ,5,clpr);


How can I get an array containing the average of the high and low?


Thanks!

 
hknight555:

I use this to get an array of the highest bar prices:

I use this to get an array of the lowest bar prices:


How can I get an array containing the average of the high and low?


Thanks!

You have to code it. 

 

I'm trying to use a for loop to get the average, but this returns 0.


    double clpr1[];
    ArraySetAsSeries(clpr1, true);
    int copied1 = CopyHigh(NULL, 0, 0, 10, clpr1);
    
    double clpr2[];
    ArraySetAsSeries(clpr2, true);
    int copied2 = CopyLow(NULL, 0, 0, 10, clpr2);

    double clprAverage[];
    int ArrayIndex = 0;
    for(ArrayIndex = ArraySize(clpr1) - 1; ArrayIndex >= 0; ArrayIndex--)
    clprAverage[ArrayIndex]= (clpr1[ArrayIndex]+clpr2[ArrayIndex])/2;

    Alert( clpr1[2] , " | ", clpr2[2] , " | " , clprAverage[2]);
 
hknight555 #:

I'm trying to use a for loop to get the average, but this returns 0.


missing one line to initiate the average array:

    double clpr1[];
    ArraySetAsSeries(clpr1, true);
    int copied1 = CopyHigh(NULL, 0, 0, 10, clpr1);
    
    double clpr2[];
    ArraySetAsSeries(clpr2, true);
    int copied2 = CopyLow(NULL, 0, 0, 10, clpr2);

    double clprAverage[];
/////////////////////////////////////////////////
    ArrayResize(clprAverage, ArraySize(clpr1));
/////////////////////////////////////////////////
    int ArrayIndex = 0;
    for(ArrayIndex = ArraySize(clpr1) - 1; ArrayIndex >= 0; ArrayIndex--)
    clprAverage[ArrayIndex]= (clpr1[ArrayIndex]+clpr2[ArrayIndex])/2;

    Alert( clpr1[2] , " | ", clpr2[2] , " | " , clprAverage[2]);