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

RSI strategy #316

Merged
merged 2 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ macd
--overbought_rsi_periods=<value> number of periods for overbought RSI (default: 25)
--overbought_rsi=<value> 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=<value> period length (default: 2m)
--min_periods=<value> min. number of history periods (default: 52)
--rsi_periods=<value> number of RSI periods
--oversold_rsi=<value> buy when RSI reaches or drops below this value (default: 30)
--overbought_rsi=<value> sell when RSI reaches or goes above this value (default: 82)
--rsi_recover=<value> allow RSI to recover this many points before buying (default: 3)
--rsi_drop=<value> allow RSI to fall this many points before selling (default: 0)
--rsi_dividend=<value> sell when RSI reaches high-water reading divided by this value (default: 2)

sar
description:
Parabolic SAR
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions extensions/strategies/rsi/_codemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
_ns: 'zenbot',

'strategies.rsi': require('./strategy'),
'strategies.list[]': '#strategies.rsi'
}
72 changes: 72 additions & 0 deletions extensions/strategies/rsi/strategy.js
Original file line number Diff line number Diff line change
@@ -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
}
}
}