PARABOLIC SAR (PSAR) strat working
#3
(09-09-2018, 11:33 PM)BotsEdge Wrote: PSAR = Parabolic SAR?

Just post it here, i am interested

Yes, Parabolic SAR,

Here it is. Hope it help:

indicator:


Code:
var Indicator = function(settings) {
 this.input = 'candle';
 //this.acceleration = 0.02;
 this.acceleration = settings.optInAcceleration;
 //this.maximum = 0.2;
 this.maximum = settings.optInMaximum;
 this.result = 0;
 this.bull = true;
 //this.start = 0.02;
 this.start = settings.optInStart;
}

Indicator.prototype.update = function(candle) {
 if(this.result == 0) {
   this.result = candle.close;
   this.low1 = candle.low;
   this.high1 = candle.high;
   this.low2 = candle.low;
   this.high2 = candle.high;
   this.hp = candle.high;
   this.lp = candle.low;
   this.af = this.start;
   return;
 }

 if(this.bull){
   this.psar = this.result + this.af * (this.hp - this.result)
 } else {
   this.psar = this.result + this.af * (this.lp - this.result)
 }

 let reverse = false;

 if(this.bull){
   if(candle.low < this.psar){
     this.bull = false;
     reverse = true;
     this.psar = this.hp;
     this.lp = candle.low;
     this.af = this.start;
   }
 } else {
   if(candle.high > this.psar){
     this.bull = true;
     reverse = true;
     this.psar = this.lp;
     this.hp = candle.high;
     this.af = this.start;
   }
 }

 if(!reverse){
   if(this.bull){
     if(candle.high > this.hp){
       this.hp = candle.high;
       this.af = Math.min(this.af + this.acceleration, this.maximum);
     }
     if(this.low1 < this.psar)
       this.psar = this.low1;
     if(this.low2 < this.psar)
       this.psar = this.low2;
   } else {
     if(candle.low < this.lp){
       this.lp = candle.low;
       this.af = Math.min(this.af + this.acceleration, this.maximum);
     }
     if(this.high1 > this.psar)
       this.psar = this.high1;
     if(this.high2 > this.psar)
       this.psar = this.high2;
   }
 }

 this.low2 = this.low1;
 this.low1 = candle.low;
 this.high2 = this.high1;
 this.high1 = candle.high;
 this.result = this.psar;
}

module.exports = Indicator;

strategy:


Code:
//mutenroch_rev2

// helpers
var _ = require('lodash');
var log = require('../core/log.js');


// let's create our own method
var method = {};

// prepare everything our method needs
method.init = function() {

 // keep state if adviced or not
 this.adviced = false;  

 // how many candles do we need as a base
 // before we can start giving advice?
 this.requiredHistory = this.tradingAdvisor.historySize;

 // define the indicators we need
 this.addIndicator('psar', 'PSAR', this.settings);
}

// what happens on every new candle?
method.update = function(candle) {
 // nothing!
}


method.check = function(candle) {
 
 this.bull = this.indicators.psar.bull;

 if(this.bull) {
   
   if(this.adviced == false){
   // new uptrend detected
   this.advice('long');
   this.adviced = true;

   }else
   this.advice();
   

 } else {
   
   if(this.adviced == true){
   // new downtrend detected
   this.advice('short');
   this.adviced = false;

   }else
   this.advice();
   }
}

module.exports = method;

settings (for .toml):


Code:
optInAcceleration = 0.02
optInMaximum = 0.2
optInStart = 0.02

B.R.
  Reply


Messages In This Thread
PARABOLIC SAR (PSAR) strat working - by mutenroch - 09-02-2018, 12:25 PM
RE: PSAR strat working - by BotsEdge - 09-09-2018, 11:33 PM
RE: PSAR strat working - by mutenroch - 09-14-2018, 10:57 PM

Forum Jump:


Users browsing this thread: