-
Notifications
You must be signed in to change notification settings - Fork 58
/
Pinescript-MultiIndicator-1
91 lines (74 loc) · 3.96 KB
/
Pinescript-MultiIndicator-1
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//@version=5
indicator(title="RSI + Money Flow Index + ADX", shorttitle="RSI+MF+ADX", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
// Indicator Switches
rsi_switch = input.bool(true, title="RSI On/Off" ,group="Visibiity Controls")
mf_switch = input.bool(true, title="Money Flow On/Off" ,group="Visibiity Controls")
adx_switch = input.bool(true, title="ADX On/Off" , group="Visibiity Controls")
// RSI
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
isBB = maTypeInput == "Bollinger Bands"
rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
plot(rsi_switch ? rsi : na, "RSI", color=#000000)
plot(rsi_switch ? rsiMA : na, "RSI-based MA", color=color.yellow)
// No Effect On Chart You can Remove It
bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)
bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)
fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(color.green, 90) : na, title="Bollinger Bands Background Fill")
// Money Flow Index
length = input.int(title="Length", defval=14, minval=1, maxval=2000, group="Money Flow Index Settings")
src = hlc3
mf = ta.mfi(src, length)
overbought=hline(80, title="Overbought", color=#787B86)
oversold=hline(20, title="Oversold", color=#787B86)
fill(overbought, oversold, color=color.rgb(126, 87, 194, 90), title="Background")
plot(mf_switch ? mf : na, "MF", color=color.purple)
// ADX
adxlen = input(14, title="ADX Smoothing" ,group="ADX Settings")
dilen = input(14, title="DI Length", group="ADX Settings")
dirmov(len) =>
adx_up = ta.change(high)
adx_down = -ta.change(low)
plusDM = na(adx_up) ? na : (adx_up > adx_down and adx_up > 0 ? adx_up : 0)
minusDM = na(down) ? na : (adx_down > adx_up and adx_down > 0 ? adx_down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
plot(adx_switch ? sig : na, color=color.red, title="ADX")
// Bollinger Bands - Lets Complicate This
bb_length = input.int(20, minval=1)
bb_src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(bb_src, bb_length)
dev = mult * ta.stdev(bb_src, bb_length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))