09-23-2018, 10:39 PM
(This post was last modified: 09-23-2018, 10:41 PM by PrimalFury.)
Is there anyone with a working bollinger bands indicator where u could use if price < bb.lower then....
I have this:
Results of theconsole.log(BB)
Indicator {
input: 'price',
settings: { optInTimePeriod: 20 },
center:
Indicator {
input: 'price',
windowLength: undefined,
prices: [ 0.00001299, NaN: 0.0000124 ],
result: 0.000025389999999999996,
age: NaN,
sum: 0.000025389999999999996 },
lower: NaN,
middle: 0.000025389999999999996,
upper: NaN }
the bb.js file in strategies/indicators :
Anyone seeing what im doing wrong or forget?
I have this:
Code:
var periodbb = 20;
strat.init = function() {
this.addIndicator('bb', 'BB', {optInTimePeriod: periodbb } );
strat.check = function(candle) {
var BB = this.indicators.bb;
console.log(BB)
Results of theconsole.log(BB)
Indicator {
input: 'price',
settings: { optInTimePeriod: 20 },
center:
Indicator {
input: 'price',
windowLength: undefined,
prices: [ 0.00001299, NaN: 0.0000124 ],
result: 0.000025389999999999996,
age: NaN,
sum: 0.000025389999999999996 },
lower: NaN,
middle: 0.000025389999999999996,
upper: NaN }
the bb.js file in strategies/indicators :
Code:
// required indicators: SMA;
// Bollinger Bands implementation;
var SMA = require('./SMA.js');
var Indicator = function(BBSettings) {
this.input = 'price';
this.settings = BBSettings;
this.center = new SMA(this.settings.TimePeriod);
this.lower=0;
this.middle=0;
this.upper=0;
}
Indicator.prototype.calcstd = function(prices, Average)
{
var squareDiffs = prices.map(function(value){
var diff = value - Average;
var sqr = diff * diff;
return sqr;
});
var sum = squareDiffs.reduce(function(sum, value){
return sum + value;
}, 0);
var avgSquareDiff = sum / squareDiffs.length;
return Math.sqrt(avgSquareDiff);
}
Indicator.prototype.update = function(price) {
this.center.update(price);
this.middle = this.center.result;
var std = this.calcstd(this.center.prices, this.middle);
this.lower = this.middle - this.settings.NbDevDn * std;
this.upper = this.middle + this.settings.NbDevUp * std;
}
module.exports = Indicator;
Anyone seeing what im doing wrong or forget?