anandanand84 / technicalindicators

A javascript technical indicators written in typescript with pattern recognition right in the browser
MIT License
2.14k stars 557 forks source link

EMA and SMA returns the same values #204

Closed xmspix closed 4 years ago

xmspix commented 4 years ago

EMA and SMA with same period returns the same result

xmspix commented 4 years ago

sorry it was my mistake i didn't reverse the close prices

tusharsinghal1610 commented 4 years ago

It still gives the same output, how did you resolve?

xmspix commented 4 years ago

hi, you should try to reverse the data...

in my case i take stocks data from yahoo, here is what i did and it worked :

export const SMA = ({ values, period }) => { return Indicator.SMA.calculate({ period: period, values: values.reverse() }).reverse()[0]; };

export const EMA = ({ values, period }) => { return Indicator.EMA.calculate({ period: period, values: values.reverse() }).reverse()[0]; };

On Thu, Mar 26, 2020 at 8:28 PM tusharsinghal1610 notifications@github.com wrote:

It still gives the same output, how did you resolve?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/anandanand84/technicalindicators/issues/204#issuecomment-604601030, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADJATXTZPJA7KG2UKANJEUDRJONDLANCNFSM4K2QR7YQ .

tusharsinghal1610 commented 4 years ago

I have my data suppose [4,5,6,7,8,9] if i use period 4 EMA gives = 7.5 (just the simple average of last four) SMA gives = 5.5 (just the simple average of first four)

actually when you are using reverse() inside function , it reverses array two times , thus gives different averages one starting , and one ending