-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgetSignals.py
78 lines (71 loc) · 3.04 KB
/
getSignals.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
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
import pandas as pd
import numpy as np
from collections import Counter
from enum import Enum
import ta
from ta.utils import dropna
import asyncio
import sys
from datetime import datetime
from pathlib import Path
from pathos.multiprocessing import ProcessingPool as Pool
import tracemalloc
import time
from pathos.threading import ThreadPool
import itertools
from functools import partial
from datetime import datetime
import indicators as ind
import os.path
from os import path
t_symbol = None
t_e_candles = pd.DataFrame()
t_candleamount = None
def saveATR(candles, candleamount, params=[], fillna=True, symbol='XBTUSD'):
for i in params:
if path.exists('IndicatorData//' + t_symbol + '//ATR//' + "p" + str(i) + '.csv') == False:
df = ind.atrseries(candles, candleamount, i)
print(df)
df.to_csv('IndicatorData//' + symbol + '//ATR//' + "p" + str(i) + ".csv", mode='w')
return
def saveKeltnerBands(candles, candleamount, params=[], symbol='XBTUSD'):
for i in params:
if path.exists('IndicatorData//' + symbol + '//Keltner//' + "BANDS_kp" + str(i[0]) + "_sma" + str(i[1]) + '.csv'):
continue
df = ind.get_keltner_bands(candles, candleamount=candleamount, kperiod=i[0], ksma=i[1])
print(df)
df.to_csv('IndicatorData//' + symbol + '//Keltner//' + "BANDS_kp" + str(i[0]) + "_sma" + str(i[1]) + '.csv', mode='w')
return
def saveKeltnerSignals(candles, candleamount, params=[], symbol='XBTUSD'):
for i in params:
if path.exists('IndicatorData//' + symbol + '//Keltner//' + "SIGNALS_kp" + str(i[0]) + "_sma" + str(i[1]) + '.csv'):
continue
signals = ind.get_keltner_signals(candles, candleamount=candleamount, kperiod=i[0], ksma=i[1])
df = pd.Series(signals, dtype=object)
print(df)
df.to_csv('IndicatorData//' + symbol + '//Keltner//' + "SIGNALS_kp" + str(i[0]) + "_sma" + str(i[1]) + '.csv', mode='w', index=False)
return
def saveEngulf_thread(params):
if path.exists('IndicatorData//' + t_symbol + '//Engulfing//' + "SIGNALS_t" + str(params[0]) + "_ignoredoji" + str(params[1]) + '.csv'):
return
signals = ind.get_engulf_signals(t_e_candles, t_candleamount, params)
df = pd.Series(signals, dtype=object)
df.to_csv('IndicatorData//' + t_symbol + '//Engulfing//' + "SIGNALS_t" + str(params[0]) + "_ignoredoji" + str(params[1]) + '.csv', mode='w', index=False)
return("thread-done")
def saveEngulfingSignals(candles, candleamount, params=[], symbol='XBTUSD'):
global t_e_candles
global t_symbol
global t_candleamount
t_e_candles = ind.candle_df(candles, candleamount)
t_symbol = symbol
t_candleamount = candleamount
epool = ThreadPool()
results = epool.uimap(saveEngulf_thread, params)
print("Computing engulfing signals for all params multithreaded...")
#DO NOT REMOVE THIS PRINT, IT IS NEEDED TO FINISH THE MULTITHREAD
result = list(results)
print(result)
return(result)
#Examples
#saveKeltnerBands(100, [10,1], [True, False])
#saveATR(100, [1,20,30])