indicator · own pane · open source
Adaptive MACD
Running…
Loading chart…
About
Adaptive MACD — fast and slow EMA lengths scale with the Efficiency Ratio. Trends compress the windows for sharper crosses; chop widens them so the MACD doesn't whipsaw.
- Histogram (h) flips are the signal; 0 line is the bias.
Source code
//@version=5
indicator("Adaptive MACD", overlay=false)
len = input.int(14, "Base length", minval=5, maxval=100)
cumAbs = ta.cum(math.abs(ta.change(close)))
sumAbs = cumAbs - cumAbs[len]
er = math.abs(close - close[len]) / math.max(sumAbs, 0.0001)
aFast = na(er) ? 12 : math.max(2, math.min(50, math.round(2 / (0.5 + er * 1.5))))
aSlow = na(er) ? 26 : math.max(aFast * 2, math.min(200, math.round(2 / (0.05 + er * 0.5))))
[m, s, h] = ta.macd(close, aFast, aSlow, 9)
macdH = h
hline(0, "Zero", color=color.gray)
p_Histogram = plot(macdH, "Histogram", color=color.gray, style=plot.style_columns)
alertcondition(ta.crossover(macdH, 0), "Histogram up", "Adaptive MACD histogram crossed above zero")
alertcondition(ta.crossunder(macdH, 0), "Histogram down", "Adaptive MACD histogram crossed below zero")
No comments yet.
Sign in to comment.