How to Get Histogram from MACD and Signal lines?

 

I successfully used the code below to get the last n values of MACD and Signal lines:

CopyBuffer(handleMACD, 0, n, inputBufferNumber, bufferMACD);
CopyBuffer(handleMACD, 1, n, inputBufferNumber, bufferSignal);

However, I also need the Histogram line.
How can I get the the last n values of the Histogram line?

MACD - Oscillators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
Moving Average Convergence/Divergence (MACD) is a trend-following dynamic indicator. It indicates the correlation between two Moving Averages of a...
 
mohammad sh: However, I also need the Histogram line.
Just compute it. histogrami = macd i - signali .
 
William Roeder #:
Just compute it. histogrami = macd i - signali .
double hist[3];
for (int i = 2; i >= 0; i--) {
   hist[i] = bufferMACD[i] - bufferSignal[i];
}

I used the code above. It seems to work. However, when I try,

double hist[n];
I get invalid index value error.
Reason: