Gekko Forum
Looking for a WORKING Bollinger Bands Indicator - Printable Version

+- Gekko Forum (https://forum.gekko.wizb.it)
+-- Forum: Gekko (https://forum.gekko.wizb.it/forum-13.html)
+--- Forum: Technical Discussion (https://forum.gekko.wizb.it/forum-23.html)
+--- Thread: Looking for a WORKING Bollinger Bands Indicator (/thread-57678.html)



Looking for a WORKING Bollinger Bands Indicator - PrimalFury - 09-23-2018

Is there anyone with a working bollinger bands indicator where u could use if price < bb.lower then....

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?


RE: Looking for a WORKING Bollinger Bands Indicator - Yoganesh - 09-26-2018

let customBBSettings = {

   optInTimePeriod: 20,
   optInNbDevUp: 2,
   optInNbDevDn: 2,
   optInMAType: 0
 };


 this.addTalibIndicator('mybb', 'bbands', customBBSettings);


this.BB = this.talibIndicators.mybb.result;
this.BB.upper = this.BB['outRealUpperBand'];
this.BB.middle = this.BB['outRealMiddleBand'];
this.BB.lower = this.BB['outRealLowerBand'];
this.bbGap = this.BB.upper - this.BB.lower;