Skip to content

Instantly share code, notes, and snippets.

@Pedro942
Created May 5, 2017 00:44
Show Gist options
  • Save Pedro942/a73491ec5a00e30edf688e7bbb6e5ef7 to your computer and use it in GitHub Desktop.
Save Pedro942/a73491ec5a00e30edf688e7bbb6e5ef7 to your computer and use it in GitHub Desktop.
MACD RSI
var method = {};
var parameters = {
short: 12,
long: 26,
signal: 9,
down: -0.001,
up: 0.001,
persistence: 1
};
var parameters1 = {
interval: 14,
low: 30,
high: 70,
persistence: 1
};
// Prepare everything our strat needs
method.init = function() {
// start of with no investment
this.currentTrend = 'short';
// add a native MACD
this.addIndicator('mynativemacd', 'MACD', parameters);
//add native RSI
this.addIndicator('mynativeRSI', 'RSI', parameters1);
}
// What happens on every new candle?
method.update = function(candle) {
// your code!
}
// For debugging purposes.
method.log = function() {
// your code!
}
// Based on the newly calculated
// information, check if we should
// update or not.
method.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') {
if (MACDsaysSELL && RSIsaysSELL) {
this.currentTrend = 'short';
this.advice('short');
}
else {}
}
else if (this.currentTrend === 'short') {
if (MACDsaysBUY && RSIsaysBUY) {
this.currentTrend = 'long';
this.advice('long');
}
else {}
}
}
module.exports = method;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment