From d62f4abe931409e59a0b3fb28ec75695c5963a7c Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 5 Jul 2018 17:26:01 +0200 Subject: [PATCH 1/5] Update strategy.js Correct code proposed in the second pull request. This code is tested and works, actually I'm using whit this modifications and all works ok. Sorry again for my error. --- extensions/strategies/rsi/strategy.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extensions/strategies/rsi/strategy.js b/extensions/strategies/rsi/strategy.js index 0107f122fe..2f48b1baf4 100644 --- a/extensions/strategies/rsi/strategy.js +++ b/extensions/strategies/rsi/strategy.js @@ -38,6 +38,10 @@ module.exports = { s.rsi_high = s.period.rsi } } + if (s.trend !== 'oversold' && s.trend !== 'long' && s.period.rsi >= s.options.overbought_rsi) { + s.rsi_high = s.period.rsi + s.trend = 'long' + } 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_divisor) { @@ -67,6 +71,9 @@ module.exports = { if (s.period.rsi <= s.options.oversold_rsi) { color = 'green' } + if (s.period.rsi >= s.options.overbought_rsi) { + color = 'white' + } cols.push(z(4, n(s.period.rsi).format('0'), ' ')[color]) } return cols From 529b9ef3705c96418994beef203eef2cf0c86dd2 Mon Sep 17 00:00:00 2001 From: diegstroyer Date: Fri, 17 Aug 2018 11:59:41 +0200 Subject: [PATCH 2/5] Optimized RSI Adding validation before execute all the conditionals --- extensions/strategies/rsi/strategy.js | 70 ++++++++++++++------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/extensions/strategies/rsi/strategy.js b/extensions/strategies/rsi/strategy.js index 2f48b1baf4..3b22f73c76 100644 --- a/extensions/strategies/rsi/strategy.js +++ b/extensions/strategies/rsi/strategy.js @@ -26,39 +26,41 @@ module.exports = { onPeriod: function (s, cb) { if (s.in_preroll) return 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 !== 'oversold' && s.trend !== 'long' && s.period.rsi >= s.options.overbought_rsi) { - s.rsi_high = s.period.rsi - s.trend = 'long' - } - 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_divisor) { - 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' - } + if (s.period.rsi <= s.options.oversold_rsi || s.period.rsi >= s.options.overbought_rsi) { + if (s.trend === 'undefined' && 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 !== 'oversold' && s.trend !== 'long' && s.period.rsi >= s.options.overbought_rsi) { + s.rsi_high = s.period.rsi + s.trend = 'long' + } + 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_divisor) { + 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() @@ -72,7 +74,7 @@ module.exports = { color = 'green' } if (s.period.rsi >= s.options.overbought_rsi) { - color = 'white' + color = 'red' } cols.push(z(4, n(s.period.rsi).format('0'), ' ')[color]) } From 75a5cbdf17d2baadbfd6038fde6ac708951d110b Mon Sep 17 00:00:00 2001 From: diegstroyer Date: Fri, 17 Aug 2018 12:12:08 +0200 Subject: [PATCH 3/5] Optimization RSI Adding validation before execute all the conditionals --- extensions/strategies/rsi/strategy.js | 70 +++++++++++++-------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/extensions/strategies/rsi/strategy.js b/extensions/strategies/rsi/strategy.js index 3b22f73c76..99c8debaab 100644 --- a/extensions/strategies/rsi/strategy.js +++ b/extensions/strategies/rsi/strategy.js @@ -26,41 +26,41 @@ module.exports = { onPeriod: function (s, cb) { if (s.in_preroll) return cb() if (typeof s.period.rsi === 'number') { - if (s.period.rsi <= s.options.oversold_rsi || s.period.rsi >= s.options.overbought_rsi) { - if (s.trend === 'undefined' && 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 !== 'oversold' && s.trend !== 'long' && s.period.rsi >= s.options.overbought_rsi) { - s.rsi_high = s.period.rsi - s.trend = 'long' - } - 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_divisor) { - 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' - } - } + if (s.period.rsi <= s.options.oversold_rsi || s.period.rsi >= s.options.overbought_rsi) { + if (s.trend === 'undefined' && 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 !== 'oversold' && s.trend !== 'long' && s.period.rsi >= s.options.overbought_rsi) { + s.rsi_high = s.period.rsi + s.trend = 'long' + } + 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_divisor) { + 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() From 6b3b3f3db0fdac72229e07687902d0109bca50c5 Mon Sep 17 00:00:00 2001 From: diegstroyer Date: Fri, 17 Aug 2018 12:21:30 +0200 Subject: [PATCH 4/5] Optimization RSI strategy --- extensions/strategies/rsi/strategy.js | 68 +++++++++++++-------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/extensions/strategies/rsi/strategy.js b/extensions/strategies/rsi/strategy.js index 99c8debaab..2c84ec450e 100644 --- a/extensions/strategies/rsi/strategy.js +++ b/extensions/strategies/rsi/strategy.js @@ -26,41 +26,39 @@ module.exports = { onPeriod: function (s, cb) { if (s.in_preroll) return cb() if (typeof s.period.rsi === 'number') { - if (s.period.rsi <= s.options.oversold_rsi || s.period.rsi >= s.options.overbought_rsi) { - if (s.trend === 'undefined' && 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 !== 'oversold' && s.trend !== 'long' && s.period.rsi >= s.options.overbought_rsi) { - s.rsi_high = s.period.rsi - s.trend = 'long' - } - 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_divisor) { - 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' - } - } + if (s.trend === 'undefined' && 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 !== 'oversold' && s.trend !== 'long' && s.period.rsi >= s.options.overbought_rsi) { + s.rsi_high = s.period.rsi + s.trend = 'long' + } + 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_divisor) { + 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() From 16c32f7a91fafbb0df4018e516f0ebc6d79dc251 Mon Sep 17 00:00:00 2001 From: diegstroyer Date: Fri, 17 Aug 2018 12:23:37 +0200 Subject: [PATCH 5/5] Optimization RSI strategy --- extensions/strategies/rsi/strategy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/strategies/rsi/strategy.js b/extensions/strategies/rsi/strategy.js index 2c84ec450e..fac5c82feb 100644 --- a/extensions/strategies/rsi/strategy.js +++ b/extensions/strategies/rsi/strategy.js @@ -26,7 +26,7 @@ module.exports = { onPeriod: function (s, cb) { if (s.in_preroll) return cb() if (typeof s.period.rsi === 'number') { - if (s.trend === 'undefined' && s.period.rsi <= s.options.oversold_rsi) { + if (s.trend === undefined && s.period.rsi <= s.options.oversold_rsi) { s.rsi_low = s.period.rsi s.trend = 'oversold' }