def calculateEMA(period, closeArray, emaArray=[]): length = len(closeArray)
nanCounter= np.count_nonzero(np.isnan(closeArray)) if not emaArray: emaArray.
extend(np.tile([np.nan], (nanCounter + period - 1))) firstema = np.mean(
closeArray[nanCounter:nanCounter + period - 1]) emaArray.append(firstema) for i
in range(nanCounter + period, length): ema = (2 * closeArray[i] + (period - 1) *
emaArray[-1]) / (period + 1) emaArray.append(ema) return np.array(emaArray) def
calculateMACD(closeArray, shortPeriod=12, longPeriod=26, signalPeriod=9): ema12
= calculateEMA(shortPeriod, closeArray, []) ema26 = calculateEMA(longPeriod,
closeArray, []) diff = ema12 - ema26 dea = calculateEMA(signalPeriod, diff, [])
macd= (diff - dea) fast_values = diff slow_values = dea diff_values = macd
return fast_values, slow_values, diff_values
Technology