Category: Indicator > Trend Identificator
The MACD indicator calculates 2 exponential moving averages of the lengths specified by the inputs FastMA and SlowMA. The difference between these 2 averages is then plotted as the MACD. This value is also averaged for the number of bars specified by the input MacdMA and then plotted as the MACDAvg. Finally, the difference between the MACD and the MACD average is calculated and plotted as the MADiff.
As a trend-following indicator, the MACD may be interpreted similarly to other moving averages. When the MACD crosses above the MACD Average, an uptrend may be beginning, indicating a buy signal. Conversely, when the MACD crosses below the MACD Average, a downtrend may be beginning. As an oscillator, the MACD can signal overbought and oversold conditions.
FastMA - Number of bars of data to be included in calculation of the fast (shorter) exponential moving average
SlowMA - Number of bars of data to be included in calculation of the slow (longer) exponential moving average
MacdMA - Number of bars used to calculate the exponential average of the MACD
INPUTS: FASTMA(12), SLOWMA(26), MACDMA(9);
PLOT1(MACD(CLOSE, FASTMA, SLOWMA), "MACD");
PLOT2(XAVERAGE(MACD(CLOSE, FASTMA, SLOWMA), MACDMA), "MACDAVG");
PLOT3(PLOT1 - PLOT2, "MADIFF");
IF PLOT3 CROSSES OVER 0 THEN
ALERT("MACD HAS GENERATED A BULLISH ALERT")
IF PLOT3 CROSSES UNDER 0 THEN
ALERT("MACD HAS GENERATED A BEARISH ALERT");