From 859535da99db8daeac2d5d63ee1d98b66ea0ec0b Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 20 Jun 2017 05:34:05 -0700 Subject: [PATCH 1/2] init RSI strategy --- extensions/strategies/rsi/_codemap.js | 6 +++ extensions/strategies/rsi/strategy.js | 72 +++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 extensions/strategies/rsi/_codemap.js create mode 100644 extensions/strategies/rsi/strategy.js diff --git a/extensions/strategies/rsi/_codemap.js b/extensions/strategies/rsi/_codemap.js new file mode 100644 index 0000000000..c17c7e3876 --- /dev/null +++ b/extensions/strategies/rsi/_codemap.js @@ -0,0 +1,6 @@ +module.exports = { + _ns: 'zenbot', + + 'strategies.rsi': require('./strategy'), + 'strategies.list[]': '#strategies.rsi' +} \ No newline at end of file diff --git a/extensions/strategies/rsi/strategy.js b/extensions/strategies/rsi/strategy.js new file mode 100644 index 0000000000..5aacbe3615 --- /dev/null +++ b/extensions/strategies/rsi/strategy.js @@ -0,0 +1,72 @@ +var z = require('zero-fill') + , n = require('numbro') + +module.exports = function container (get, set, clear) { + return { + name: 'rsi', + description: 'Attempts to buy low and sell high by tracking RSI high-water readings.', + + getOptions: function () { + this.option('period', 'period length', String, '2m') + this.option('min_periods', 'min. number of history periods', Number, 52) + this.option('rsi_periods', 'number of RSI periods', 14) + this.option('oversold_rsi', 'buy when RSI reaches or drops below this value', Number, 30) + this.option('overbought_rsi', 'sell when RSI reaches or goes above this value', Number, 82) + this.option('rsi_recover', 'allow RSI to recover this many points before buying', Number, 3) + this.option('rsi_drop', 'allow RSI to fall this many points before selling', Number, 0) + this.option('rsi_dividend', 'sell when RSI reaches high-water reading divided by this value', Number, 2) + }, + + calculate: function (s) { + get('lib.rsi')(s, 'rsi', s.options.rsi_periods) + }, + + onPeriod: function (s, cb) { + if (typeof s.period.rsi === 'number') { + if (s.trend !== 'oversold' && s.trend !== 'long' && s.period.rsi <= s.options.oversold_rsi) { + s.rsi_low = s.period.rsi + s.trend = 'oversold' + } + if (s.trend === 'oversold') { + s.rsi_low = Math.min(s.rsi_low, s.period.rsi) + if (s.period.rsi >= s.rsi_low + s.options.rsi_recover) { + s.trend = 'long' + s.signal = 'buy' + s.rsi_high = s.period.rsi + } + } + if (s.trend === 'long') { + s.rsi_high = Math.max(s.rsi_high, s.period.rsi) + if (s.period.rsi <= s.rsi_high / s.options.rsi_dividend) { + s.trend = 'short' + s.signal = 'sell' + } + } + if (s.trend === 'long' && s.period.rsi >= s.options.overbought_rsi) { + s.rsi_high = s.period.rsi + s.trend = 'overbought' + } + if (s.trend === 'overbought') { + s.rsi_high = Math.max(s.rsi_high, s.period.rsi) + if (s.period.rsi <= s.rsi_high - s.options.rsi_drop) { + s.trend = 'short' + s.signal = 'sell' + } + } + } + cb() + }, + + onReport: function (s) { + var cols = [] + if (typeof s.period.rsi === 'number') { + var color = 'grey' + if (s.period.rsi <= s.options.oversold_rsi) { + color = 'green' + } + cols.push(z(4, n(s.period.rsi).format('0'), ' ')[color]) + } + return cols + } + } +} \ No newline at end of file From acd729f48b7e635ec3176cfa92ae9ff7758b35c5 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 20 Jun 2017 05:44:25 -0700 Subject: [PATCH 2/2] readme for rsi strat --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 59bc1ee1fd..f568f7b789 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,19 @@ macd --overbought_rsi_periods= number of periods for overbought RSI (default: 25) --overbought_rsi= sold when RSI exceeds this value (default: 70) +rsi + description: + Attempts to buy low and sell high by tracking RSI high-water readings. + options: + --period= period length (default: 2m) + --min_periods= min. number of history periods (default: 52) + --rsi_periods= number of RSI periods + --oversold_rsi= buy when RSI reaches or drops below this value (default: 30) + --overbought_rsi= sell when RSI reaches or goes above this value (default: 82) + --rsi_recover= allow RSI to recover this many points before buying (default: 3) + --rsi_drop= allow RSI to fall this many points before selling (default: 0) + --rsi_dividend= sell when RSI reaches high-water reading divided by this value (default: 2) + sar description: Parabolic SAR @@ -339,6 +352,14 @@ The moving average convergence divergence calculation is a lagging indicator, us - It's not firing multiple 'buy' or 'sold' signals, only one per trend, which seems to lead to a better quality trading scheme. - Especially when the bot will enter in the middle of a trend, it avoids buying unless it's the beginning of the trend. +### About the rsi strategy + +Attempts to buy low and sell high by tracking RSI high-water readings. + +- Effective in sideways markets or markets that tend to recover after price drops. +- Risky to use in bear markets, since the algorithm depends on price recovery. +- If the other strategies are losing you money, this strategy may perform better, since it basically "reverses the signals" and anticipates a reversal instead of expecting the trend to continue. + ### About the sar strategy Uses a [Parabolic SAR](http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:parabolic_sar) indicator to trade when SAR trend reverses.