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

Approximation "averages" doesn't return undefined #7377

Closed
pawelfus opened this issue Nov 8, 2017 · 2 comments
Closed

Approximation "averages" doesn't return undefined #7377

pawelfus opened this issue Nov 8, 2017 · 2 comments

Comments

@pawelfus
Copy link
Contributor

@pawelfus pawelfus commented Nov 8, 2017

Issue

When approximating to days, line breaks in the Bollinger Bands indicator shouldn't show up.

This may not be necessary bug in the approximation method, but according to sum approx, we should return undefined:

                sum: function(arr) {
                    var len = arr.length,
                        ret;

                    // 1. it consists of nulls exclusively
                    if (!len && arr.hasNulls) {
                        ret = null;
                        // 2. it has a length and real values
                    } else if (len) {
                        ret = 0;
                        while (len--) {
                            ret += arr[len];
                        }
                    }
                    // 3. it has zero length, so just return undefined
                    // => doNothing()

                    return ret;
                },

I think docs should be updated too.

FYI @KacperMadej

Live demo with steps to reproduce

http://jsfiddle.net/nLtpemxy/1/

Workaround

http://jsfiddle.net/nLtpemxy/

Set custom approximation:

        approximation: function(top, middle, bottom) {
          var ret = [];

          Highcharts.each(arguments, function(arr) {
            ret.push(Highcharts.approximations.average(arr));
          });

          return middle.length ? ret : undefined;
        }
@lotsawa
Copy link

@lotsawa lotsawa commented Nov 9, 2017

Thanks @pawelfus!

The workaround works well. However please notice that this problem also occurs on price envelope, and maybe other more.

Thanks again for the workaround.

@pawelfus
Copy link
Contributor Author

@pawelfus pawelfus commented Nov 10, 2017

Thank you for info! Resolving this issue will fix all indicators that use averages (like Bollinger bands, Price envelopes etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.