Specification
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)
Responded
1
Rating
Projects
479
33%
Arbitration
24
42%
/
46%
Overdue
6
1%
Busy
2
Rating
Projects
925
48%
Arbitration
301
59%
/
25%
Overdue
123
13%
Loaded
3
Rating
Projects
570
36%
Arbitration
64
20%
/
58%
Overdue
147
26%
Free
4
Rating
Projects
440
26%
Arbitration
123
21%
/
56%
Overdue
96
22%
Loaded
5
Rating
Projects
10
20%
Arbitration
0
Overdue
0
Free
6
Rating
Projects
96
24%
Arbitration
9
22%
/
22%
Overdue
12
13%
Working
7
Rating
Projects
402
38%
Arbitration
82
41%
/
20%
Overdue
70
17%
Working
8
Rating
Projects
6
17%
Arbitration
0
Overdue
1
17%
Free
Project information
Budget
30+ USD
Customer
Placed orders1
Arbitrage count0