oransel / node-talib

A technical analysis library for node.js
GNU Lesser General Public License v3.0
904 stars 149 forks source link

BBands upper and lower bands incorrect if input too small #69

Closed hunglee closed 4 years ago

hunglee commented 6 years ago

I've tested with BTC-ADA data, it return 3 lines are the same data

var close = [ 0.00001467,
  0.00001465,
  0.00001466,
  0.00001467,
  0.00001466,
  0.00001471,
  0.00001474,
  0.0000147,
  0.00001469,
  0.00001469,
  0.0000147,
  0.00001471,
  0.00001476,
  0.00001472,
  0.00001472,
  0.0000147,
  0.00001473,
  0.00001473,
  0.00001471,
  0.0000147,
  0.00001469,
  0.00001469 ];
talib.execute({
                    name: "BBANDS",
                    inReal: close,
                    startIdx: 0,
                    endIdx: close.length - 1,
                    optInTimePeriod: 20,
                    optInNbDevUp: 2,
                    optInNbDevDn: 2,
                    optInMAType: 0
                }, function (err, result) {
if (err) {
                        console.log('error', err);
                    }
                    else {
                        console.log(result);
                    }

});

then the results

{ begIndex: 19, nbElement: 3, result: { outRealUpperBand: [ 0.000014700999999999999, 0.000014702, 0.000014703999999999997 ], outRealMiddleBand: [ 0.000014700999999999999, 0.000014702, 0.000014703999999999997 ], outRealLowerBand: [ 0.000014700999999999999, 0.000014702, 0.000014703999999999997 ] } }

laserlance commented 6 years ago

I bet if you change the optInTimePeriod to something smaller then you will see a difference. The issue you present is not unique to this wrapper; it is a feature of the underlying TA-LIB library of functions. If you don't give enough data, or if your optInTimePeriod is too high for the amount of data you present to the function, then you should not expect accurate results.