-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript astrahvh.lua
110 lines (82 loc) · 3.79 KB
/
script astrahvh.lua
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
instrument { name = "script astrahvh", overlay = true, icon = "indicators:BB" }
period = input (20, "Perodo", input.integer, 1)
devs = input (1, "Desvio Padro", input.integer, 1)
overbought = input (1, "Sobrecompra", input.double, -2, 2, 0.1, false)
oversold = input (0, "Sobrevenda", input.double, -2, 2, 0.1, false)
source = input (1, "Fonte do Indicador", input.string_selection, inputs.titles)
fn = input (1, "Mdia Mvel", input.string_selection, averages.titles)
input_group {
"RSI",
period1 = input (7, "Perodo", input.integer, 1),
source1 = input (1, "Fonte do Indicador", input.string_selection, inputs.titles),
fn1 = input (averages.ssma, "Mdia Mvel", 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
-- Bandas de Bollinger
middle = averageFunction(sourceSeries, period)
scaled_dev = devs * stdev(sourceSeries, period)
top = middle + scaled_dev
bottom = middle - scaled_dev
bbr = (sourceSeries - bottom) / (top - bottom)
-- RSI
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
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))))
-- Mdias Mveis
MAfast = 9
MAslow = 21
short = ema(close, MAfast)
long = ema(close, MAslow)
-- CCI
period_cci = 20
nom = hlc3 - sma(hlc3, period_cci)
denom = mad(hlc3, period_cci) * 0.015
cci = nom / denom
-- **MACD**
MACDfast = 12
MACDslow = 26
MACDsignal = 9
macd_line = ema(close, MACDfast) - ema(close, MACDslow)
signal_line = ema(macd_line, MACDsignal)
-- **ADX**
ADXperiod = 14
dmi_plus = rma(max(high - high[1], 0), ADXperiod)
dmi_minus = rma(max(low[1] - low, 0), ADXperiod)
dx = abs(dmi_plus - dmi_minus) / (dmi_plus + dmi_minus) * 100
adx = rma(dx, ADXperiod)
-- **Condies para COMPRA**
pu = (cci > CCIupLevel) and
(rsi > RSIupLevel) and
(bbr > BBupLevel) and
(open[1] > short[1] and close[1] > short[1]) and
(macd_line > signal_line) and
(adx > 25 and dmi_plus > dmi_minus)
-- **Condies para VENDA**
pd = (cci < CCIdnLevel) and
(rsi < RSIdnLevel) and
(bbr < BBdnLevel) and
(open[1] < short[1] and close[1] < short[1]) and
(macd_line < signal_line) and
(adx > 25 and dmi_minus > dmi_plus)
-- Exibir sinais no grfico
plot_shape(pd, "Venda", shape_style.triangledown, shape_size.large, 'red', shape_location.abovebar, 0, 'VENDER', 'red')
plot_shape(pu, "Compra", shape_style.triangleup, shape_size.large, 'green', shape_location.belowbar, 0, 'COMPRAR', 'green')
print(pu)