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