2025-06-13[五]:4EMA+MACD指標‧‧
2025-06-13[五]:4EMA+MACD指標‧‧
//@version=5
indicator("EMA & MACD", overlay=false)
// Opsi untuk menampilkan atau menyembunyikan indikator
showEMA1 = input(true, title="Show EMA 1")
showEMA2 = input(true, title="Show EMA 2")
showEMA3 = input(true, title="Show EMA 3")
showEMA4 = input(true, title="Show EMA 4")
showMACD = input(true, title="Show MACD")
// Input indikator EMA
// ------------------------
ema1Length = input.int(20, title="EMA 1 Length")
ema2Length = input.int(50, title="EMA 2 Length")
ema3Length = input.int(100, title="EMA 3 Length")
ema4Length = input.int(200, title="EMA 4 Length")
// Hitung EMA
ema1 = ta.ema(close, ema1Length)
ema2 = ta.ema(close, ema2Length)
ema3 = ta.ema(close, ema3Length)
ema4 = ta.ema(close, ema4Length)
// Plot EMA dengan overlay paksa
plot(showEMA1 ? ema1 : na, color=color.green , title="EMA 1", linewidth=2, style=plot.style_line ,force_overlay = true)
plot(showEMA2 ? ema2 : na, color=color.orange , title="EMA 2", linewidth=2, style=plot.style_line ,force_overlay = true)
plot(showEMA3 ? ema3 : na, color=color.red , title="EMA 3", linewidth=2, style=plot.style_line ,force_overlay = true)
plot(showEMA4 ? ema4 : na, color=color.white , title="EMA 4", linewidth=2, style=plot.style_line ,force_overlay = true)
// Input indikator MACD
// ------------------------
fast_length = input(title = "Fast Length", defval = 6)
slow_length = input(title = "Slow Length", defval = 13)
src = input(title = "Source", defval = close)
signal_length = input.int(title = "Signal Smoothing", minval = 1, maxval = 50, defval = 9, display = display.data_window)
sma_source = input.string(title = "Oscillator MA Type", defval = "EMA", options = ["SMA", "EMA"], display = display.data_window)
sma_signal = input.string(title = "Signal Line MA Type", defval = "EMA", options = ["SMA", "EMA"], display = display.data_window)
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
alertcondition(hist[1] >= 0 and hist < 0, title = 'Rising to falling', message = 'The MACD histogram switched from a rising to falling state')
alertcondition(hist[1] <= 0 and hist > 0, title = 'Falling to rising', message = 'The MACD histogram switched from a falling to rising state')
hline(0, "Zero Line", color = color.new(#787B86, 50))
plot(hist, title = "Histogram", style = plot.style_columns, color = (hist >= 0 ? (hist[1] < hist ? #26A69A : #B2DFDB) : (hist[1] < hist ? #FFCDD2 : #FF5252)))
plot(macd, title = "MACD", color = #2962FF)
plot(signal, title = "Signal", color = #FF6D00)
留言
張貼留言