1

I want to calculate ema in python. I searched on google a lot of functions are available. But I want to calculate ema with single value not serie values. I did it with pine script on tradingview here is my pinescript code:

dd = lowest (low, 4)//get lowest value in 4 series

yy = highest (high, 5)//get highest value in 5 series

diff = yy - dd

ortdiff = ema(ema(diff,3),3)

How can ı calculate ema of single values? Any library pr any function for calculate ema? Thanks

ema calculations on pinescripts:

pine_ema(src, length) =>

alpha = 2 / (length + 1)

sum = 0.0

sum := na(sum[1]) ? sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])

How can I calculate these functions on python?

MMT
  • 21
  • 3
  • I might've misunderstood your question, but what do you mean by calculating an EMA of a single value? What do you expect to get in return? In any case, if you're working with series (which it seems you are, given your Pine code), I suggest working with pandas library for python, it's the library to work with on timeseries data. – Crispy Holiday Apr 16 '22 at 16:14
  • https://stackoverflow.com/questions/488670/calculate-exponential-moving-average-in-python – Bijin Abraham Apr 16 '22 at 16:29
  • Hi, thanks for your comment @CrispyHoliday I want to calculate my code emas. for example ema(3.12,3) //3.12 ema value to be calculated, 3 period – MMT Apr 16 '22 at 16:32
  • The `ema` of a single value is that value. The `ema` is an average, and the average of the set `[x]` is `x`. – Tim Roberts Apr 16 '22 at 21:52
  • Tradingview calculate pinescript code on my questions. pine_ema(src, length) => alpha = 2 / (length + 1) sum = 0.0 sum := na(sum[1]) ? sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1]) How can I calculate these functions on python? – MMT Apr 16 '22 at 22:54

0 Answers0