-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZMACD_RSI_KDJ
65 lines (57 loc) · 2.68 KB
/
ZMACD_RSI_KDJ
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//@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)
sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])
// Plot colors
col_macd = input(#000000, "MACD Line ", group="Color Settings", inline="MACD")
col_signal = input(#ffffff, "Signal Line ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
// 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
hline(0, "Zero Line", color=color.new(#787B86, 50))
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
plot(macd, title="MACD", color=col_macd, linewidth=2)
plot(signal, title="Signal", color=col_signal, linewidth=2)
//KDJ
ilong = input(9, title="period")
isig = input(3, title="signal")
bcwsma(s,l,m) =>
_s = s
_l = l
_m = m
_bcwsma=1.0
_bcwsma := (_m*_s+(_l-_m)*nz(_bcwsma[1]))/_l
_bcwsma
c = close
h = ta.highest(high, ilong)
l = ta.lowest(low,ilong)
RSV = 100*((c-l)/(h-l))
pK = bcwsma(RSV, isig, 1)
pD = bcwsma(pK, isig, 1)
pJ = 3*pK-2*pD
pkm=(pK-50)*0.1
pdm=(pD-50)*0.1
pjm=(pJ-50)*0.1
plot(pkm, linewidth=2, color= color.new(#1E88E5,transp=0))
plot(pdm, linewidth=2, color=color.new(#FF6F00,transp=0))
plot(pjm, color=color.rgb(153, 0, 255), linewidth=2)
bgcolor(pjm>pdm? color.new(color.green,50) : color.new(color.red, 50))
h0 = hline(3,linestyle=hline.style_dashed,linewidth=2)
h1 = hline(-3,linestyle=hline.style_dashed,linewidth=2)
//RSI
rsi_length = input(14, title="RSI")
rsi = (ta.rsi(close, rsi_length)-50)*0.1
rsi_color = rsi >= 2.5 or rsi <= -2.5 ? color.new(#000000, 0):color.new(#000000, 80)
plot(rsi, color=rsi_color, linewidth=2, style=plot.style_circles, title="RSI")