Adding custom trading indicator to own strategy - SuperUserek - 02-08-2018
Hi there, i am very new to Gekko. As a programmer (hobbyist) i was going to make my own bot till i have found Gekko, but lack of documentation and js (yet - so far i know basics so i will get on it quick) decided to use it and apply my trading skills. And make my own stategies with as less loss as possible.
But to start of i need some of you to clarify some things for me.
There is simple strategy config in js to be customised.
Code: // Let's create our own strategy
var strat = {};
// Prepare everything our strat needs
strat.init = function() {
// your code!
}
// What happens on every new candle?
strat.update = function(candle) {
// your code!
}
// For debugging purposes.
strat.log = function() {
// your code!
}
// Based on the newly calculated
// information, check if we should
// update or not.
strat.check = function(candle) {
// your code!
}
// Optional for executing code
// after completion of a backtest.
// This block will not execute in
// live use as a live gekko is
// never ending.
strat.end = function() {
// your code!
}
module.exports = strat;
I have had a look inside some strategies. And still doesnt understand where did you get variables and results from your own strategy.
For instance i would like to use Tulib and use some of indicators for example BBands.
So to code above as i have found on your webside to use tulib indicators example as followes
Code: method.init = function() {
var customMACDSettings = {
optInFastPeriod: 10,
optInSlowPeriod: 21,
optInSignalPeriod: 9
}
// add the indicator to the strategy
this.addTulipIndicator('mymacd', 'macd', customMACDSettings);
}
method.check = function() {
// use indicator results
var result = this.tulipIndicators.mymacd.result;
var macddiff = result['macd'] - result['macdSignal'];
// do something with macdiff
}
I have put this together for Bbands indicator but got some questions about it can you have a look on the code?
Code: // Let's create our own strategy
var custommethod = {};
// ---------------------------- INIT
custommethod.init = function() {
var customBBandsParams = {
//I THINK this should be taken from: https://gekko.wizb.it/docs/strategies/tulip_indicators.html
optInTimePeriod: 20,
optInNbStdDevs: 2,
}
//this.addTulipIndicator('FUNCNAME,INDICNAME,PARAMSIFNEEDED')? <-- IS THIS RIGHT THINKING?
this.addTulipIndicator('mybbands', 'bbands', customBBandsParams);
}
// What happens on every new candle?
custommethod.update = function(candle) {
// LETS SKIP THAT FOR NOW
// CHECKING PRICE OR SOMETHING ELSE
}
// For debugging purposes.
custommethod.log = function() {
// LETS SKIP THAT FOR NOW
}
custommethod.check = function(candle) {
// your code!
var result = this.tulipIndicators.mybbands.result;
var resultofbbands = result['bbands'];
//==============??????????????? HOW DO I GET DETAILS ABOUT IT TO CONSOLE?
//==============??????????????? WHERE DID YOU GET LETS SAY 3 LINES top middle bottom one printed out to actually print numbers of possition of those bands??
log.debug('RESULT FROM INDICATOR BBANDS');
log.debug(result);
log.debug('RESULT OF BBANDS');
log.debug(resultofbbands);
}
/////////////////EXAMPLE WITH MACD FROM JS FILES
//method.check = function() {
// // use indicator results
// QUESTION WHERE DID YOU GOT THOSE VARIABLES SUCH AS RESULT MACD and MACDSIGNAL?
// ANY WEBSITE / MANUAL ???
// var macddiff = result['macd'] - result['macdSignal'];
// var result = this.tulipIndicators.mymacd.result;
//
// // do something with macdiff
//}
// Optional for executing code
// after completion of a backtest.
// This block will not execute in
// live use as a live gekko is
// never ending.
custommethod.end = function() {
// your code!
}
module.exports = custommethod;
This is my first attempt and i have loads of questions
Thanks for looking, hope you can clarify my questions and make it brighter for me and others.
//I have already added this post but in wrong place.
config.js - susitronix - 02-09-2018
Hi
The config.js is only used by the CLI-cmd version of gekko.
The --ui version is fully configurable from within the ui.
for tulip indicators you find docu here:
https://gekko.wizb.it/docs/strategies/tulip_indicators.html
there is also strategies that already using tulip lib for ease...
|