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

Inconsistency with bbands indicator #60

Open
me60732 opened this issue Aug 15, 2019 · 1 comment
Open

Inconsistency with bbands indicator #60

me60732 opened this issue Aug 15, 2019 · 1 comment

Comments

@me60732
Copy link

me60732 commented Aug 15, 2019

There seems to be an inconsistency with bbands indicator compared to other indicators concerning the output. I don't know if the problem is within this library or tulip itself.

All indicators i've useds thus far return outputs that match the length of the inputs I feed into it minus any lag time. however the bbands indicator only returning 3 outputs (low, middle, high) with only one period (the last period). this makes it difficult and inefficient to plot on a graph.

sample code:
let bbands = await tulip.indicators.bbands.indicator([stock.close], [20, 2]);

console.log(stock.close.length) // = whatever 10,000
console.log(bbands[0].length) // =1
console.log(bbands[1].length) // =1
console.log(bbands[2].length) // =1

whereas any other indicator i've used MACD for example the above output arrays almost match the length of the initial input (the difference being the lag of the indicator)

@codeplea
Copy link
Member

There seems to be an inconsistency with bbands indicator compared to other indicators concerning the output. I don't know if the problem is within this library or tulip itself.

No. This library is used by thousands of traders. Maybe the problem isn't with it, but in fact lies within your code.

All indicators i've useds thus far return outputs that match the length of the inputs I feed into it minus any lag time. however the bbands indicator only returning 3 outputs (low, middle, high) with only one period (the last period). this makes it difficult and inefficient to plot on a graph.

All of the indicators work the same. Most have a lag, and you can find that amount with the start function:

console.log(tulind.indicators.bbands.start([20, 2])); //19

This means that a 20-period bbands will be 19 bars shorten than its input.

Now let's try a complete example to show that it works:

var tulind = require('tulind');

var close = [2,5,4,5,2,3,5,2,4,5,2,5,4,2,5,2,3,2,3,2,3,2,5,2,1,2,4,2,5,2,5];

console.log("Output will be this much shorten than input:");
console.log(tulind.indicators.bbands.start([20, 2]));

tulind.indicators.bbands.indicator([close], [20, 2], function (err, bbands) {
  if (err) console.log(err);

  console.log("Input length:");
  console.log(close.length);
  console.log("Output length:");
  console.log(bbands[0].length);
  console.log(bbands[1].length);
  console.log(bbands[2].length);

});

Note how that example is complete in that anybody can copy/paste and run it? That way we're all on the same page. Also see that we implement error handling. It's good practice to have error handling before accusing someone of having broken code.

If we run it, we get:

Output will be this much shorten than input:
19
Input length:
31
Output length:
12
12
12

Of course you want to use the await syntax, so we can rewrite the complete example as:

var tulind = require('tulind');
var close = [2,5,4,5,2,3,5,2,4,5,2,5,4,2,5,2,3,2,3,2,3,2,5,2,1,2,4,2,5,2,5];

var test = async function () {
  let bbands
  try {
    bbands = await tulind.indicators.bbands.indicator([close], [20, 2]);

    console.log("Input length:");
    console.log(close.length);
    console.log("Output length:");
    console.log(bbands[0].length);
    console.log(bbands[1].length);
    console.log(bbands[2].length);
  } catch (err) {
    console.log("Error");
    console.log(err);
  }
};

test();

Again, notice that the code is complete in that anybody can copy/paste and run it. Again, we check for errors. And again, it produces the expected output:

Input length:
31
Output length:
12
12
12

So where does that leave us? I have no doubt that your code isn't working. However, I can't run your code as you didn't provide a complete example. It's missing the async function, the inputs, and error handling. I expect you may have something weird going on with your inputs, and if you bothered to check for errors you would be pointed in the right direction. But that's just my speculation. Please give it another try and report back. If it's still broken, post a complete example and I'll be able to help you.

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

No branches or pull requests

2 participants