add WMA algorithm with bitbank bot
This commit is contained in:
2
algorithm/__init__.py
Normal file
2
algorithm/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from algorithm.wma import WMA
|
||||
from algorithm.status import Status
|
4
algorithm/status.py
Normal file
4
algorithm/status.py
Normal file
@@ -0,0 +1,4 @@
|
||||
class Status:
|
||||
def __init__(self):
|
||||
self.price = 0
|
||||
self.candles = {"1m": [], "1h": []}
|
22
algorithm/wma.py
Normal file
22
algorithm/wma.py
Normal file
@@ -0,0 +1,22 @@
|
||||
class WMA:
|
||||
def __init__(self, unit, period, width):
|
||||
self._unit = unit
|
||||
self._period = period
|
||||
self._width = width
|
||||
|
||||
def judge(self, status):
|
||||
cands = status.candles[self._unit]
|
||||
sum = 0
|
||||
den = 0
|
||||
for i in range(min(self._period-1, len(cands)-1)):
|
||||
sum += cands[i+1][3] * (i+1)
|
||||
den += i+1
|
||||
avg = sum / den
|
||||
price = cands[0][3]
|
||||
|
||||
width = price * self._width
|
||||
diff = price - avg
|
||||
if diff < 0:
|
||||
return max(-1, diff/width) # sell
|
||||
else:
|
||||
return min(1, diff/width) # buy
|
Reference in New Issue
Block a user