Your EMA uses the result from yesterday so this needs to be kept. Maybe rather use a list like so (this can certainly be cleaned and improved upon, I just changed the ema_helper):
def ema_helper(prices, N, k, length):
if len(prices) == length-N:
return prices[0]
res_ema = [p for p in prices[:N]] # this keeps the ema
for t in range(N, length):
res_ema.append(prices[t] * k + res_ema[t-1] * (1 - k))
return res_ema
This produces
[22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29, 22.264545454545452, 22.287355371900823, 22.304199849737035, 22.359799877057576, 22.541654444865287, 22.815899091253414, 22.98573562011643, 23.139238234640715, 23.286649464706038, 23.349076834759483, 23.434699228439577, 23.513844823268744, 23.538600309947153, 23.475218435411307, 23.406996901700158, 23.3929974650274, 23.263361562295145, 23.233659460059663, 23.082085012776083, 22.916251374089523]
for your dataset. (I assume you have taken it from Moving Averages), the values correspond.
If you just need the last value you can also use (no need for a list here):
def ema_helper(prices, N, k, length):
if len(prices) == length-N:
return prices[0]
res_ema = prices[N-1]
for t in range(N, length):
res_ema = (prices[t] * k + res_ema * (1 - k))
return res_ema
which gives 22.916251374089523
(or just take the last list item res_ema[-1]
).