09-15-2018, 08:55 AM
(09-15-2018, 04:10 AM)askmike Wrote: Can you share the strategy and the market? I like to reproduce this.
For sure!
in the config.js just modified the market/currency/asset and removed the strat settings block as they are fixed in the indicator .js
The market.db is too big to be uploaded (as said in a promp) what can I do?
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) {
console.log('Bull:', this.bull, 'PSAR res:', this.indicators.psar.result, 'Close:', candle.close);
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;
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;
thanks!