-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMACD [Gu5]
44 lines (39 loc) · 1.98 KB
/
MACD [Gu5]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//@version=4
// Created by @gu5tavo71 09/2019
// Github repo https://github.com/gu5tavo/Tradingview
// Disclaimer: I am not a financial advisor.
// For purpose educate only
// If you have had a positive experience, you can buy me a beer ;)
// BTC: 1MbHMN63WnsFYEavsGK4nMWSUoEiuiScny
// Paypal: https://www.paypal.me/gu5tavo71
///////////////////////////////////////////////////////////////
study(title="MACD [Gu5]", shorttitle= "MACD", overlay = false)
//Input
fast_length = input(title = "Fast Length", type = input.integer, defval = 21)
slow_length = input(title = "Slow Length", type = input.integer, defval = 55)
src = input(title="Source", type = input.source, defval = close)
signal_length = input(title="Signal Smoothing", type = input.integer, minval = 1, maxval = 50, defval = 14)
sma_source = input(title="Simple MA(Oscillator)", type = input.bool, defval = false)
sma_signal = input(title="Simple MA(Signal Line)", type = input.bool, defval = false)
showalert = input(defval = true, title="Show Alert")
//Setting
Color02 = #f57f17ff//Orange 100%
Color10 = #006400//Green
Color11 = #00640080//Green 50%
Color12 = #006400ff//Green 100%
Color20 = #8B0000//Red
Color21 = #8B000080//Red 50%
Color22 = #8B0000ff//Red 100%
Color31 = #808080//Gray
fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal
colorhist = hist >= 0 ? (hist[1] < hist ? Color10 : Color11) : (hist[1] < hist ? Color21 : Color20)
crossmacd = cross (macd, signal)
//Drawing
plot(hist, title="Histogram", style = plot.style_columns, color = colorhist)
plot(macd, title="MACD", color = Color12, linewidth = 3)
plot(signal, title="Signal", color = Color22, linewidth = 3)
plot(showalert and crossmacd ? signal : na, style = plot.style_cross, linewidth = 4, color = Color02, title = "Cross")