简体   繁体   中英

Binance api python ema calculation

after much searching I still can't find the problem and the solution. I am trying to get ema values ​​for various periods and none of them match the values ​​I see on Binance. I know that matching them 100% is impossible because it is a value that is affected by previous values ​​etc. However, my values ​​differ too much and I have too many accumulated values ​​for the difference to be so great. First of all I have a webSocket listening for the klines of a pair with a period of 15 minutes. Throughout the minutes I receive values ​​that I do not use until I receive the closing of said period. At that moment I take the market closing value and apply it in this formula:

(current_price * (2 / (n + 1))) + (last_ema * (1 - (2 / (n + 1))))

Being:

  • current_price: The current closing price
  • last_ema: The ema value calculated in the previous close
  • n: Ema value that I want to calculate (12, 26, etc.)

With each period close I make this calculation taking the previous value of the previous close. That is, I take the previous n values, if not I always have the previous value stored to use it in the current closing and thus I update the ema value for the values ​​I need. I know it is impossible to get 100% accuracy, but I get too big of a difference. Is there something I'm not doing right?

And, in case of using an external api, do you know any one to which you can pass the previous value and the new closure for the calculation and avoid having to pass all the data? Thank you

Solved. Problem was formula. With correct data no I have correct information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM