09-23-2018, 10:42 PM
Is there anyone with a working bollinger bands indicator where u could use if price < b.lower then....
I have this:
Code:
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:
Anyone seeing what im doing wrong or forget?
I have this:
Code:
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:
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?