forked from sofienkaabar/the-book-of-trading-strategies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Appendix_II_ATR.py
42 lines (27 loc) · 1.09 KB
/
Appendix_II_ATR.py
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
# Requires the definition of Simple Moving Average & Exponential Moving Average
def atr(Data, lookback, high, low, close, where):
# Adding the required columns
Data = adder(Data, 1)
# True Range Calculation
for i in range(len(Data)):
try:
Data[i, where] = max(Data[i, high] - Data[i, low],
abs(Data[i, high] - Data[i - 1, close]),
abs(Data[i, low] - Data[i - 1, close]))
except ValueError:
pass
Data[0, where] = 0
# Average True Range Calculation
Data = ema(Data, 2, lookback, where, where + 1)
# Cleaning
Data = deleter(Data, where, 1)
Data = jump(Data, lookback)
return Data
# Trading parameters
horizon = 'H1'
# Mass imports
my_data = mass_import(0, horizon)
# Calculating the ATR
my_data = atr(my_data, 10, 1, 2, 3, 4)
if sigchart == True:
indicator_plot_double(my_data, 3, 4, name = assets[2], name_ind = '', window = 250)