Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Gekko papertrade issue #1958

Closed
manjeetsinghcodz opened this issue Feb 22, 2018 · 5 comments
Closed

Gekko papertrade issue #1958

manjeetsinghcodz opened this issue Feb 22, 2018 · 5 comments
Labels

Comments

@manjeetsinghcodz
Copy link

manjeetsinghcodz commented Feb 22, 2018

Hi geeks,

I hope you're all doing well.

I have used this code to create a strategy and test my gekko bot. I'm doing a papertrade with this configuration config.js below on commandline :

######################################################################################

var config = {};

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// GENERAL SETTINGS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

config.debug = true; // for additional logging / debugging

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// WATCHING A MARKET
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

config.watch = {
exchange: 'binance',
currency: 'BTC',
asset: 'BCC',

// You can set your own tickrate (refresh rate).
// If you don't set it, the defaults are 2 sec for
// okcoin and 20 sec for all other exchanges.
// tickrate: 20
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CONFIGURING TRADING ADVICE
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

config.tradingAdvisor = {
enabled: true,
// method: 'MACD',
method: 'StochRSI_MACD_BB',
candleSize: 1,
historySize: 3,
adapter: 'sqlite'
}

// Exponential Moving Averages settings:
config.DEMA = {
// EMA weight (α)
// the higher the weight, the more smooth (and delayed) the line
short: 10,
long: 21,
// amount of candles to remember and base initial EMAs on
// the difference between the EMAs (to act as triggers)
thresholds: {
down: -0.025,
up: 0.025
}
};

// MACD settings:
config.MACD = {
// EMA weight (α)
// the higher the weight, the more smooth (and delayed) the line
short: 10,
long: 21,
signal: 9,
// the difference between the EMAs (to act as triggers)
thresholds: {
down: -0.025,
up: 0.025,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 1
}
};

// PPO settings:
config.PPO = {
// EMA weight (α)
// the higher the weight, the more smooth (and delayed) the line
short: 12,
long: 26,
signal: 9,
// the difference between the EMAs (to act as triggers)
thresholds: {
down: -0.025,
up: 0.025,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 2
}
};

// Uses one of the momentum indicators but adjusts the thresholds when PPO is bullish or bearish
// Uses settings from the ppo and momentum indicator config block
config.varPPO = {
momentum: 'TSI', // RSI, TSI or UO
thresholds: {
// new threshold is default threshold + PPOhist * PPOweight
weightLow: 120,
weightHigh: -120,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 0
}
};

// RSI settings:
config.RSI = {
interval: 14,
thresholds: {
low: 30,
high: 70,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 1
}
};

// TSI settings:
config.TSI = {
short: 13,
long: 25,
thresholds: {
low: -25,
high: 25,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 1
}
};

// Ultimate Oscillator Settings
config.UO = {
first: {weight: 4, period: 7},
second: {weight: 2, period: 14},
third: {weight: 1, period: 28},
thresholds: {
low: 30,
high: 70,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 1
}
};

// CCI Settings
config.CCI = {
constant: 0.015, // constant multiplier. 0.015 gets to around 70% fit
history: 90, // history size, make same or smaller than history
thresholds: {
up: 100, // fixed values for overbuy upward trajectory
down: -100, // fixed value for downward trajectory
persistence: 0 // filter spikes by adding extra filters candles
}
};

// StochRSI settings
//config.StochRSI = {
//interval: 3,
//thresholds: {
// low: 20,
// high: 80,
// How many candle intervals should a trend persist
// before we consider it real?
//persistence: 3
// }
//};

config.StochRSI_MACD_BB = {
interval: 14,
short: 12,
long: 26,
signal: 9,
bbands: {
TimePeriod: 20,
NbDevDn: 2,
NbDevUp: 2,
persistence_upper: 10,
persistence_lower: 10,
},
thresholds: {
low: 20,
high: 80,
down: -0.1,//-2,//-0.1,
up: 0.1,//1.5,//0.25,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 2
}
};

// custom settings:
config.custom = {
my_custom_setting: 10,
}

config['talib-macd'] = {
parameters: {
optInFastPeriod: 10,
optInSlowPeriod: 21,
optInSignalPeriod: 9
},
thresholds: {
down: -0.025,
up: 0.025,
}
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CONFIGURING PLUGINS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// do you want Gekko to simulate the profit of the strategy's own advice?
config.paperTrader = {
enabled: true,
// report the profit in the currency or the asset?
reportInCurrency: true,
// start balance, on what the current balance is compared with
simulationBalance: {
// these are in the unit types configured in the watcher.
asset: 1,
currency: 100,
},
// how much fee in % does each trade cost?
feeMaker: 0.15,
feeTaker: 0.25,
feeUsing: 'maker',
slippage: 0.05,
}

config.performanceAnalyzer = {
enabled: true,
riskFreeReturn: 5
}
config.trader = {.
enabled: false,
key: 'XXXXXX',
secret: 'XXXXXX',
username: '',
}
config.adviceLogger = {
enabled: false,
muteSoft: true // disable advice printout if it's soft
}

config.pushover = {
enabled: false,
sendPushoverOnStart: false,
muteSoft: true, // disable advice printout if it's soft
tag: '[GEKKO]',
key: '',
user: ''
}

// want Gekko to send a mail on buy or sell advice?
config.mailer = {
enabled: false, // Send Emails if true, false to turn off
sendMailOnStart: true, // Send 'Gekko starting' message if true, not if false

email: '', // Your Gmail address
muteSoft: true, // disable advice printout if it's soft

// You don't have to set your password here, if you leave it blank we will ask it
// when Gekko's starts.
//
// NOTE: Gekko is an open source project < https://github.com/askmike/gekko >,
// make sure you looked at the code or trust the maintainer of this bot when you
// fill in your email and password.
//
// WARNING: If you have NOT downloaded Gekko from the github page above we CANNOT
// guarantuee that your email address & password are safe!

password: '', // Your Gmail Password - if not supplied Gekko will prompt on startup.

tag: '[GEKKO] ', // Prefix all email subject lines with this

        //       ADVANCED MAIL SETTINGS
        // you can leave those as is if you
        // just want to use Gmail

server: 'smtp.gmail.com', // The name of YOUR outbound (SMTP) mail server.
smtpauth: true, // Does SMTP server require authentication (true for Gmail)
// The following 3 values default to the Email (above) if left blank
user: '', // Your Email server user name - usually your full Email address '[email protected]'
from: '', // '[email protected]'
to: '', // '[email protected], [email protected]'
ssl: true, // Use SSL (true for Gmail)
port: '', // Set if you don't want to use the default port
}

config.pushbullet = {
// sends pushbullets if true
enabled: false,
// Send 'Gekko starting' message if true
sendMessageOnStart: true,
// disable advice printout if it's soft
muteSoft: true,
// your pushbullet API key
key: 'xxx',
// your email, change it unless you are Azor Ahai
email: '[email protected]',
// will make Gekko messages start mit [GEKKO]
tag: '[GEKKO]'
};

config.kodi = {
host: 'http://ip-or-hostname:8080/jsonrpc',
enabled: false,
sendMessageOnStart: true,
}

config.ircbot = {
enabled: false,
emitUpdates: false,
muteSoft: true,
channel: '#your-channel',
server: 'irc.freenode.net',
botName: 'gekkobot'
}

config.telegrambot = {
enabled: false,
emitUpdates: false,
token: 'YOUR_TELEGRAM_BOT_TOKEN',
botName: 'gekkobot'
}

config.twitter = {
// sends pushbullets if true
enabled: false,
// Send 'Gekko starting' message if true
sendMessageOnStart: false,
// disable advice printout if it's soft
muteSoft: false,
tag: '[GEKKO]',
// twitter consumer key
consumer_key: '',
// twitter consumer secret
consumer_secret: '',
// twitter access token key
access_token_key: '',
// twitter access token secret
access_token_secret: ''
};

config.xmppbot = {
enabled: false,
emitUpdates: false,
client_id: 'jabber_id',
client_pwd: 'jabber_pw',
client_host: 'jabber_server',
client_port: 5222,
status_msg: 'I'm online',
receiver: 'jabber_id_for_updates'
}

config.campfire = {
enabled: false,
emitUpdates: false,
nickname: 'Gordon',
roomId: null,
apiKey: '',
account: ''
}

config.redisBeacon = {
enabled: false,
port: 6379, // redis default
host: '127.0.0.1', // localhost
channelPrefix: '',
broadcast: [
'candle'
]
}

config.slack = {
enabled: false,
token: '',
sendMessageOnStart: true,
muteSoft: true,
channel: '' // #tradebot
}

config.ifttt = {
enabled: false,
eventName: 'gekko',
makerKey: '',
muteSoft: true,
sendMessageOnStart: true
}

config.candleWriter = {
enabled: false
}

config.adviceWriter = {
enabled: false,
muteSoft: true,
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CONFIGURING ADAPTER
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

config.adapter = 'sqlite';
config.sqlite = {
path: 'plugins/sqlite',
dataDirectory: 'history',
version: 0.1,
journalMode: require('./web/isWindows.js') ? 'DELETE' : 'WAL',
dependencies: []
}
// Postgres adapter example config (please note: requires postgres >= 9.5):
config.postgresql = {
path: 'plugins/postgresql',
version: 0.1,
connectionString: 'postgres://user:pass@localhost:5432', // if default port
database: null, // if set, we'll put all tables into a single database.
schema: 'public',
dependencies: [{
module: 'pg',
version: '6.1.0'
}]
}

// Mongodb adapter, requires mongodb >= 3.3 (no version earlier tested)
config.mongodb = {
path: 'plugins/mongodb',
version: 0.1,
connectionString: 'mongodb://mongodb/gekko', // connection to mongodb server
dependencies: [{
module: 'mongojs',
version: '2.4.0'
}]
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CONFIGURING BACKTESTING
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
config.backtest = {
// daterange: 'scan',
daterange: {
//Add by manjeet for backtesting
from: "2018-02-01 00:00:00",
to: "2018-02-10 00:00:00",
//
batchSize: 50
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CONFIGURING IMPORTING
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

config.importer = {
daterange: {
// NOTE: these dates are in UTC
from: "2018-02-01 00:00:00",
to: "2018-02-10 00:00:00"
}
}
config['I understand that Gekko only automates MY OWN trading strategies'] = true;

module.exports = config;

####################################################################################

On the strategies directory i have the StochRSI_MACD_BB.js it :

####################################################################################

cat strategies/StochRSI_MACD_BB.js
/*
StochRSI - SamThomp 11/06/2014
(updated by askmike) @ 30/07/2016
*/
// helpers
var _ = require('lodash');
var log = require('../core/log.js');

var RSI = require('./indicators/RSI.js');

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

// prepare everything our method needs
method.init = function() {
this.interval = this.settings.interval;

this.trend = {
direction: 'none',
duration: 0,
persisted: false,
adviced: false
};

this.requiredHistory = this.tradingAdvisor.historySize;

// define the indicators we need
this.addIndicator('rsi', 'RSI', { interval: this.interval });
this.addIndicator('macd', 'MACD', this.settings);
//commented my manjeet
this.addIndicator('bb', 'BB', this.settings.bbands);
this.RSIhistory = [];
}

// what happens on every new candle?
method.update = function(candle) {
this.rsi = this.indicators.rsi.result;

this.RSIhistory.push(this.rsi);

if(_.size(this.RSIhistory) > this.interval)
	// remove oldest RSI value
	this.RSIhistory.shift();

this.lowestRSI = _.min(this.RSIhistory);
this.highestRSI = _.max(this.RSIhistory);
this.stochRSI = ((this.rsi - this.lowestRSI) / (this.highestRSI - this.lowestRSI)) * 100;

}

// for debugging purposes log the last
// calculated parameters.
method.log = function(candle) {
var digits = 8;

log.debug('calculated StochRSI properties for candle:');
log.debug('\t', 'rsi:', this.rsi.toFixed(digits));
log.debug("StochRSI min:\t\t" + this.lowestRSI.toFixed(digits));
log.debug("StochRSI max:\t\t" + this.highestRSI.toFixed(digits));
log.debug("StochRSI Value:\t\t" + this.stochRSI.toFixed(2));
//MACD

var macd = this.indicators.macd;
var diff = macd.diff;
var signal = macd.signal.result;
    var BB = this.indicators.bb;
var price = candle.close;
var macddiff = this.indicators.macd.result;
    //BB
    var BB = this.indicators.bb;
   //BB.lower; BB.upper; BB.middle are your line values 

var MACDsaysBUY = macddiff > this.settings.thresholds.up;
var MACDsaysSELL = macddiff <= this.settings.thresholds.down;
var StochRSIsaysBUY = this.stochRSI < this.settings.thresholds.low;
var StochRSIsaysSELL = this.stochRSI >= this.settings.thresholds.high;
var BBsayBUY=price >= (BB.middle-(BB.middle-BB.lower)/4);
var BBsaySELL=price <= BB.lower; //>= BB.upper || price <= BB.lower 

log.debug('calculated MACD properties for candle:');
log.debug('\t', 'short:', macd.short.result.toFixed(digits));
log.debug('\t', 'long:', macd.long.result.toFixed(digits));
log.debug('\t', 'macd:', diff.toFixed(digits));
log.debug('\t', 'signal:', signal.toFixed(digits));
log.debug('\t', 'macdiff:', macd.result.toFixed(digits));

    log.debug('\t', 'BB.lower:', BB.lower.toFixed(digits));
log.debug('\t', 'BB.middle:', BB.middle.toFixed(digits));
log.debug('\t', 'BB.upper:', BB.upper.toFixed(digits));
log.debug('\t', 'price', price.toFixed(digits));
if(BBsayBUY) {
	log.debug('\t', 'BBsaysBUY');
}
if(MACDsaysBUY) {
	log.debug('\t', 'MACDsaysBUY');
}
if(StochRSIsaysBUY) {
	log.debug('\t', 'StochRSIsaysBUY');
}
if(BBsaySELL) {
	log.debug('\t', 'BBsaysSELL');
}
if(MACDsaysSELL) {
	log.debug('\t', 'MACDsaysSELL');
}
if(StochRSIsaysSELL) {
	log.debug('\t', 'StochRSIsaysSELL');
}
if(MACDsaysSELL && StochRSIsaysSELL) {
   		log.debug('\t', 'StochRSIsaysSELL and MACDsaysSELL');
}
if(MACDsaysBUY && StochRSIsaysBUY && BBsayBUY) {
   		log.debug('\t', 'MACDsaysBUY and StochRSIsaysBUY and BBsaysBUY');
}

}

method.check = function(candle) {
//MACD
var macddiff = this.indicators.macd.result;
//BB
var BB = this.indicators.bb;
//BB.lower; BB.upper; BB.middle are your line values
var price = candle.close;
//buy when stochRSI in low and MACD in up
//short->sell, long->buy

var MACDsaysBUY = macddiff > this.settings.thresholds.up;
var MACDsaysSELL = macddiff <= this.settings.thresholds.down;
var StochRSIsaysBUY = this.stochRSI < this.settings.thresholds.low;
var StochRSIsaysSELL = this.stochRSI >= this.settings.thresholds.high;
var BBsayBUY=price >= (BB.middle-(BB.middle-BB.lower)/4);
var BBsaySELL=price <= BB.lower; //>= BB.upper || price <= BB.lower 
    if(MACDsaysSELL && StochRSIsaysSELL) {
	// new trend detected
	if(this.trend.direction !== 'high')
		this.trend = {
			duration: 0,
			persisted: false,
			direction: 'high',
			adviced: false
		};

	this.trend.duration++;

	log.debug('In high since', this.trend.duration, 'candle(s)');

	if(this.trend.duration >= this.settings.thresholds.persistence )
		this.trend.persisted = true;

	if(this.trend.persisted && !this.trend.adviced) {
		this.trend.adviced = true;
		this.advice('short');
	} else
		this.advice();

} 
//buy when stochRSI in high and MACD in low	
else if(MACDsaysBUY && StochRSIsaysBUY && BBsayBUY) {

	// new trend detected
	if(this.trend.direction !== 'low')
		this.trend = {
			duration: 0,
			persisted: false,
			direction: 'low',
			adviced: false
		};

	this.trend.duration++;

	log.debug('In low since', this.trend.duration, 'candle(s)');

	if(this.trend.duration >= this.settings.thresholds.persistence)
		this.trend.persisted = true;

	if(this.trend.persisted && !this.trend.adviced) {
		this.trend.adviced = true;
		this.advice('long');
	} else
		this.advice();

} else {
	// trends must be on consecutive candles
	this.trend.duration = 0;
	log.debug('In no trend');

	this.advice();
}

}
module.exports = method;
####################################################################################

On the

####################################################################################
On the directory stategies/indicators, i have the BB.js script
cat strategies/indicators/BB.js
// 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;

#####################################################################################

Now when i'n running a papertrader enable and trader disabled, There are not buy or sell info but also debug info about StockRSIsaybuy or sell or BBsaybUY or sell. I let that commandline papertrader run the whole night. but not a single result of a buy or sell. Please find the log of the papertrade attached
trade.log.gz

Is there any body to please assist me ?

Thank you so much.

@askmike
Copy link
Owner

askmike commented Feb 22, 2018

would you be able to post the strat somewhere else and format it? I can't read it like this.

@manjeetsinghcodz
Copy link
Author

manjeetsinghcodz commented Feb 22, 2018

Alright buddzz , i can give it to you on text files :

bb.txt
StockRSI_bb.txt

And the files seems to be updated by yourself 💃

@dpblnt
Copy link

dpblnt commented Mar 1, 2018

Should be good strat, but gave me no trade results in backtesting it on binance ETH/ETC from 2018-01-01 to 2018-02-01, not even with parameter tunings.

@stale
Copy link

stale bot commented Oct 24, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you feel this is very a important issue please reach out the maintainer of this project directly via e-mail: gekko at mvr dot me.

@stale stale bot added the wontfix label Oct 24, 2018
@stale stale bot closed this as completed Nov 2, 2018
@dcpulse
Copy link

dcpulse commented Dec 12, 2018

uncaughtException TypeError: Cannot read property 'TimePeriod' of undefined
at new Indicator (E:\gekko-develop\strategies\indicators\BB.js:7:41)

Any idea with this error?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants