Calculate a Moving Average from Arrays

 
Hello everyone,

I would like to calculate a moving average, not from prices but from 2 histograms which accumulate values, in this way :

(Hist1a) if current low < previous low --> = 1 
             if current low ≮ previous low --> = 0 

(Hist2a) if current vol < previous vol --> = 1 
             if current vol ≮ previous vol --> = 0 

(Hist1b) : as long as Hist1a[n] = 1 & Hist1a[n-1] = 1 --> = 1 + Hist1a[n-1] otherwise 0 

(Hist2b) : as long as Hist2a[n] = 1 & Hist2a[n-1] = 1 --> = 1 + Hist2a[n-1] otherwise 0


MA = Hist1b + Hist2b

It seems that this is not possible on the same window because the histograms would sometimes be superimposed, is there a way or is it impossible ?


Thanks for your help
 
Basic example:
// Indicator 1: Hist1b
int Hist1a(int i) {
    if (Low[i] < Low[i-1]) return 1;
    else return 0;
}

int Hist1b(int i) {
    if (Hist1a(i) == 1 && Hist1a(i-1) == 1)
        return 1 + Hist1b(i-1);
    else
        return 0;
}

// Indicator 2: Hist2b
int Hist2a(int i) {
    if (Volume[i] < Volume[i-1]) return 1;
    else return 0;
}

int Hist2b(int i) {
    if (Hist2a(i) == 1 && Hist2a(i-1) == 1)
        return 1 + Hist2b(i-1);
    else
        return 0;
}

// Indicator 3: Moving Average
double MA(int i) {
    return Hist1b(i) + Hist2b(i);
}


 

Hello, thank you for your message

I tried but there is no indicator displayed

Reason: