Rewrite the macd(trading view) code on mt5

MQL5 指标 脚本

指定

rewrite the macd(trading view) code on mt5

//@version=5
indicator(title="Moving Average Convergence Divergence", shorttitle="MACD", timeframe="", timeframe_gaps=true)
// Getting inputs
fast_length = input(title = "Fast Length", defval = 12)
slow_length = input(title = "Slow Length", defval = 26)
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)


反馈

1
开发者 1
等级
(468)
项目
530
33%
仲裁
28
39% / 43%
逾期
7
1%
繁忙
2
开发者 2
等级
(563)
项目
932
47%
仲裁
302
59% / 25%
逾期
124
13%
繁忙
3
开发者 3
等级
(254)
项目
573
36%
仲裁
64
20% / 58%
逾期
147
26%
空闲
4
开发者 4
等级
(236)
项目
440
26%
仲裁
125
21% / 57%
逾期
96
22%
工作中
5
开发者 5
等级
(14)
项目
22
36%
仲裁
1
0% / 0%
逾期
0
空闲
6
开发者 6
等级
(52)
项目
97
24%
仲裁
10
20% / 20%
逾期
12
12%
工作中
7
开发者 7
等级
(256)
项目
417
38%
仲裁
86
44% / 19%
逾期
71
17%
繁忙
8
开发者 8
等级
(6)
项目
8
13%
仲裁
0
逾期
1
13%
空闲

项目信息

预算
30+ USD
开发人员
27 USD