-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathBO indicator.lua
More file actions
82 lines (56 loc) · 2.41 KB
/
BO indicator.lua
File metadata and controls
82 lines (56 loc) · 2.41 KB
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
instrument { name = "BO indicator", overlay = true, icon = "indicators:BB" }
period = input (20, "front.period", input.integer, 1)
devs = input (1, "front.newind.stddev", input.integer, 1)
overbought = input (1, "front.overbought", input.double, -2, 2, 0.1, false)
oversold = input (0, "front.oversold", input.double, -2, 2, 0.1, false)
source = input (1, "front.ind.source", input.string_selection, inputs.titles)
fn = input (1, "front.newind.average", input.string_selection, averages.titles)
input_group {
"RSI",
period1 = input (7, "front.period", input.integer, 1),
source1 = input (1, "front.ind.source", input.string_selection, inputs.titles),
fn1 = input (averages.ssma, "front.newind.average", input.string_selection, averages.titles),
color = input { default = "#B42EFF", type = input.color },
width = input { default = 1, type = input.line_width}
}
local sourceSeries = inputs [source]
local averageFunction = averages [fn]
local sourceSeries1 = inputs [source1]
local averageFunction1 = averages [fn1]
CCIupLevel= 100
CCIdnLevel=-100
BBupLevel=1
BBdnLevel=0
RSIupLevel=70
RSIdnLevel=30
middle = averageFunction (sourceSeries, period)
scaled_dev = devs * stdev (sourceSeries, period)
top = middle + scaled_dev
bottom = middle - scaled_dev
bbr = (sourceSeries - bottom) / (top - bottom)
delta = sourceSeries1 - sourceSeries1 [1]
up1 = averageFunction (max (delta, 0), period)
down1 = averageFunction (max (-delta, 0), period)
rs = up1 / down1
rsi = 100 - 100 / (1 + rs)
src = close
len = 7
RSIupLevel=70
RSIdnLevel=30
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi1 = iff(down == 0 , 100 , iff( up == 0 , 0 , 100 - (100 / (1 + up / down))))
--rsi = (down == 0 , 100 ,iff( up == 0 , 0 ,iff( 100 - (100 / (1 + up / down)))))
MAfast=9
MAslow=21
short = ema(close, MAfast)
long = ema(close, MAslow)
period_cci = 20
nom = hlc3 - sma (hlc3, period_cci)
denom = mad (hlc3, period_cci) * 0.015
cci = nom / denom
pu= (cci>CCIupLevel) and (rsi>RSIupLevel ) and (bbr>BBupLevel) and (open[1] > short[1] and close[1]>short[1])
pd= (cci<CCIdnLevel) and (rsi < RSIdnLevel) and (bbr < BBdnLevel) and (open[1]< short[1] and close[1]<short[1])
plot_shape(pd, "short", shape_style.triangledown, shape_size.large, 'red', shape_location.abovebar,0,'SELL', 'red')
plot_shape(pu, "long", shape_style.triangleup, shape_size.large, 'green', shape_location.belowbar,0,'BUY', 'green')
print(pu)