-
Notifications
You must be signed in to change notification settings - Fork 294
/
chartlib.py
33 lines (22 loc) · 902 Bytes
/
chartlib.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
import os, pandas
def is_consolidating(df, percentage=2):
recent_candlesticks = df[-15:]
max_close = recent_candlesticks['Close'].max()
min_close = recent_candlesticks['Close'].min()
threshold = 1 - (percentage / 100)
if min_close > (max_close * threshold):
return True
return False
def is_breaking_out(df, percentage=2.5):
last_close = df[-1:]['Close'].values[0]
if is_consolidating(df[:-1], percentage=percentage):
recent_closes = df[-16:-1]
if last_close > recent_closes['Close'].max():
return True
return False
for filename in os.listdir('datasets/daily'):
df = pandas.read_csv('datasets/daily/{}'.format(filename))
if is_consolidating(df, percentage=2.5):
print("{} is consolidating".format(filename))
if is_breaking_out(df):
print("{} is breaking out".format(filename))