Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MACD doesn't work with shortPeriod: 8 and longPeriod: 16 #8365

Closed
faisalferoz opened this Issue May 22, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@faisalferoz
Copy link

faisalferoz commented May 22, 2018

Expected behaviour

MACD should work with shortPeriod set to 8 and longPeriod set to 16

Actual behaviour

It ends up with an exception

[Error] TypeError: undefined is not an object (evaluating 'k[a+b.shortPeriod+1][0]')
	getValues (macd.js:17:174)
	c (indicators.js:10:474)
	init (indicators.js:11:476)
	init (macd.js:13:199)
	initSeries (highstock.js:241:373)
	(anonymous function) (highstock.js:266)
	forEach
	each (highstock.js:28:210)
	firstRender (highstock.js:266)
	(anonymous function) (highstock.js:241:246)
	fireEvent (highstock.js:30:502)
	init (highstock.js:240)
	getArgs (highstock.js:239:471)
	Chart (highstock.js:239:271)
	stockChart (highstock.js:530:358)
	(anonymous function) (_display:81)
	i (jquery-3.1.1.min.js:2:27989)
	fireWith (jquery-3.1.1.min.js:2:28751)
	A (jquery-3.1.1.min.js:4:14215)
	(anonymous function) (jquery-3.1.1.min.js:4:16493)

Live demo with steps to reproduce

http://jsfiddle.net/90dza0cd/

Product version

Highstock 6

Affected browser(s)

All

@faisalferoz

This comment has been minimized.

Copy link
Author

faisalferoz commented May 22, 2018

I think the issue is here - https://github.com/highcharts/highstock-release/blob/master/indicators/macd.src.js#L408

Where the shortEMA's index is calculated by adding params.shortPeriod and 1 to the iterator index which will result in it being greater then the length of shortEMA array.

The fix should be to make it i + params.shortPeriod - 1 instead.

@sebastianbochan

This comment has been minimized.

Copy link
Contributor

sebastianbochan commented May 23, 2018

Hi @faisalferoz,
Thank you for the reporting, I will debug it as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.