-
-
Save askmike/5e5e10c538f617ecb2544217eab76647 to your computer and use it in GitHub Desktop.
Strategy MACD + RSI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's create our own strategy | |
var strat = {}; | |
var parameters = { | |
short: 12, | |
long: 26, | |
signal: 9, | |
down: 0, | |
up: 0, | |
persistence: 1 | |
}; | |
var parameters1 = { | |
interval: 14, | |
low: 30, | |
high: 70, | |
persistence: 2 | |
}; | |
// Prepare everything our strat needs | |
strat.init = function() { | |
// start of with no investment | |
this.currentTrend = 'short'; | |
// your code! | |
// add a native MACD | |
this.addIndicator('mynativemacd', 'MACD', parameters); | |
//add native RSI | |
this.addIndicator('mynativeRSI', 'RSI', parameters1); | |
} | |
// 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() { | |
// your code! | |
//setting vars for MACD results | |
var MACD = this.indicators.mynativemacd.macd; | |
var MACDsaysBUY = parameters.down < MACD; | |
var MACDsaysSELL = parameters.up > MACD; | |
// setting vars for RSI results | |
var RSI = this.indicators.mynativeRSI.rsi; | |
var RSIsaysBUY = RSI > parameters1.high; | |
var RSIsaysSELL = RSI < parameters1.low; | |
/// Setting conditions | |
if (this.currentTrend === 'long') { | |
// maybe we need to advice short now? | |
// only if BOTH MACD and RSI and CCI say so: | |
if (MACDsaysSELL && RSIsaysSELL) { | |
this.currentTrend = 'short'; | |
this.advice('short') | |
} | |
} else if (this.currentTrend === 'short') { | |
// maybe we need to advice long now? | |
// only if BOTH MACD and RSI and CCI say so: | |
if (MACDsaysBUY && RSIsaysBUY) { | |
this.currentTrend = 'long'; | |
this.advice('long') | |
} | |
} | |
} | |
module.exports = strat; |
Can somebody walk me through getting this running in gekko? I thought I had it but I get the classic child process has died error in terminal.
What I did was made a copy of custom.js in the strategies folder. and pasted the revised code from here into the original custom.js and tried running it in the UI.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i just wondering how to know whether an indicator has 3 parameters rather than 2?
as explain in example above, why RSI has 4 parameters?(interval, low, high, persistence)?
i have read 'talib' file inside core folder, but didnt get any clue how to determine involved parameter of an indicator.