[SHARE] Simple RSI BULL/BEAR strategy
#39
Lightbulb 
New mod, ADX.

So susitronix and 0mathew0 had me thinking about ROC and ADX thus a new idea was formed that these two pretty much have already talked about.

The idea is simple: What if there is a rapid change that somehow points to there being a more sudden positive or negative trend?
Since this happens all the time one should be able to squeeze a bit more out of such periods of time.

ROC, ADX and CMO was tested but it seems ADX was easier to get better results out of.

Updated 12th of february 00:37 (GMT+1).

--

Backtests


XRP-USDT, dec 2017 - feb 03 2018
https://i.imgur.com/Tipm0pc.png
Better performance, but not insannely much as with ETH furhter below

Settings:
Code:
/* TEMP: set params */
this.settings.SMA_long = 1000;
this.settings.SMA_short = 50;

this.settings.BULL_RSI = 10; // timeperiod
this.settings.BULL_RSI_high = 80;
this.settings.BULL_RSI_low = 60;

this.settings.BEAR_RSI = 15; // timeperiod
this.settings.BEAR_RSI_high = 50;
this.settings.BEAR_RSI_low = 20;

this.settings.ADX = 3; // timeperiod
this.settings.ADX_high = 70;
this.settings.ADX_low = 50;


ETH-USDT, 2016-01-01 - 2017-10-05 (1 year and 10 months, Poloniex)
https://i.imgur.com/7QNXUOU.png
The modification seems to have some merit, performance increased from an awesome +61 828% to an insane +94 153% (!)

ETH-USDT, 2015-08-08 - 2017-11-07 (2 years and 3 months, Poloniex)
https://i.imgur.com/L2iPfHV.png
An even longer backtest. Note that we achieved a basically out-of-this-world performance of +4 449 031% (over +4.4 million percent)

Same settings as previous was used.

ETH-USDT, 2015-08-08 - 2017-11-07 (2 years and 3 months, Poloniex)
https://i.imgur.com/bB33jX4.jpg
An even longer backtest. Note that we achieved an even more out-of-this-world performance of +83 573 824% (over +83 million percent)

Settings of candle size changefrom 15 to 5 minutes.


NEO-USDT: 2017-12-01 - 2018-02-03
https://i.imgur.com/1kwoOPi.png
Performance was worse then the original strategy, still beat 'the market' though.


--

JS

File also attached as .js.txt (since this forum doesn't allow JS-attachments).
You can download that and just remove the .txt extension.

Code:
/*
    RSI Bull and Bear + ADX modifier
    1. Use different RSI-strategies depending on a longer trend
    2. But modify this slighly if shorter BULL/BEAR is detected
    -
    12 feb 2017
    -
    (CC-BY-SA 4.0) Tommie Hansen
    https://creativecommons.org/licenses/by-sa/4.0/
*/

// req's
var log = require ('../core/log.js');
var config = require ('../core/util.js').getConfig();

// strategy
var strat = {
    
    /* INIT */
    init: function()
    {
        this.name = 'RSI Bull and Bear + ADX';
        this.requiredHistory = config.tradingAdvisor.historySize;
        this.resetTrend();        
        
        // debug? set to flase to disable all logging/messages/stats (improves performance)
        this.debug = false;
        
        // performance
        config.backtest.batchSize = 1000; // increase performance
        config.silent = true;
        config.debug = false;
        
        // SMA
        this.addTulipIndicator('maSlow', 'sma', { optInTimePeriod: this.settings.SMA_long });
        this.addTulipIndicator('maFast', 'sma', { optInTimePeriod: this.settings.SMA_short });
        
        // RSI
        this.addTulipIndicator('BULL_RSI', 'rsi', { optInTimePeriod: this.settings.BULL_RSI });
        this.addTulipIndicator('BEAR_RSI', 'rsi', { optInTimePeriod: this.settings.BEAR_RSI });
        
        // ADX
        this.addTulipIndicator('ADX', 'adx', { optInTimePeriod: this.settings.ADX })
        
        
        // debug stuff
        this.startTime = new Date();
        
        // add min/max if debug
        if( this.debug ){
            this.stat = {
                adx: { min: 1000, max: 0 },
                bear: { min: 1000, max: 0 },
                bull: { min: 1000, max: 0 }
            };
        }
        
    }, // init()
    
    
    /* RESET TREND */
    resetTrend: function()
    {
        var trend = {
            duration: 0,
            direction: 'none',
            longPos: false,
        };
    
        this.trend = trend;
    },
    
    
    /* get low/high for backtest-period */
    lowHigh: function( val, type )
    {
        let cur;
        if( type == 'bear' ) {
            cur = this.stat.bear;
            if( val < cur.min ) this.stat.bear.min = val; // set new
            else if( val > cur.max ) this.stat.bear.max = val;
        }
        else if( type == 'bull' ) {
            cur = this.stat.bull;
            if( val < cur.min ) this.stat.bull.min = val; // set new
            else if( val > cur.max ) this.stat.bull.max = val;
        }
        else {
            cur = this.stat.adx;
            if( val < cur.min ) this.stat.adx.min = val; // set new
            else if( val > cur.max ) this.stat.adx.max = val;
        }
    },
    
    
    /* CHECK */
    check: function()
    {
        // get all indicators
        let ind = this.tulipIndicators,
            maSlow = ind.maSlow.result.result,
            maFast = ind.maFast.result.result,
            rsi,
            adx = ind.ADX.result.result;
        
        
            
        // BEAR TREND
        if( maFast < maSlow )
        {
            rsi = ind.BEAR_RSI.result.result;
            let rsi_hi = this.settings.BEAR_RSI_high,
                rsi_low = this.settings.BEAR_RSI_low;
            
            // ADX trend strength?
            if( adx > this.settings.ADX_high ) rsi_hi = rsi_hi + 15;
            else if( adx < this.settings.ADX_low ) rsi_low = rsi_low -5;
                
            if( rsi > rsi_hi ) this.short();
            else if( rsi < rsi_low ) this.long();
            
            if(this.debug) this.lowHigh( rsi, 'bear' );
        }

        // BULL TREND
        else
        {
            rsi = ind.BULL_RSI.result.result;
            let rsi_hi = this.settings.BULL_RSI_high,
                rsi_low = this.settings.BULL_RSI_low;
            
            // ADX trend strength?
            if( adx > this.settings.ADX_high ) rsi_hi = rsi_hi + 5;        
            else if( adx < this.settings.ADX_low ) rsi_low = rsi_low -5;
                
            if( rsi > rsi_hi ) this.short();
            else if( rsi < rsi_low )  this.long();
            if(this.debug) this.lowHigh( rsi, 'bull' );
        }
        
        // add adx low/high if debug
        if( this.debug ) this.lowHigh( adx, 'adx');
    
    }, // check()
    
    
    /* LONG */
    long: function()
    {
        if( this.trend.direction !== 'up' ) // new trend? (only act on new trends)
        {
            this.resetTrend();
            this.trend.direction = 'up';
            this.advice('long');
            if( this.debug ) log.info('Going long');
        }
        
        if( this.debug )
        {
            this.trend.duration++;
            log.info('Long since', this.trend.duration, 'candle(s)');
        }
    },
    
    
    /* SHORT */
    short: function()
    {
        // new trend? (else do things)
        if( this.trend.direction !== 'down' )
        {
            this.resetTrend();
            this.trend.direction = 'down';
            this.advice('short');
            if( this.debug ) log.info('Going short');
        }
        
        if( this.debug )
        {
            this.trend.duration++;
            log.info('Short since', this.trend.duration, 'candle(s)');
        }
    },
    
    
    /* END backtest */
    end: function()
    {
        let seconds = ((new Date()- this.startTime)/1000),
            minutes = seconds/60,
            str;
            
        minutes < 1 ? str = seconds.toFixed(2) + ' seconds' : str = minutes.toFixed(2) + ' minutes';
        
        log.info('====================================');
        log.info('Finished in ' + str);
        log.info('====================================');
    
        // print stats and messages if debug
        if(this.debug)
        {
            let stat = this.stat;
            log.info('BEAR RSI low/high: ' + stat.bear.min + ' / ' + stat.bear.max);
            log.info('BULL RSI low/high: ' + stat.bull.min + ' / ' + stat.bull.max);
            log.info('ADX min/max: ' + stat.adx.min + ' / ' + stat.adx.max);
        }
        
    }
    
};

module.exports = strat;


TOML
Should be placed @ /gekko/config/strategies/RSI_BULL_BEAR_ADX.toml

Code:
# SMA Trends
SMA_long = 1000
SMA_short = 50

# BULL
BULL_RSI = 10
BULL_RSI_high = 80
BULL_RSI_low = 60

# BEAR
BEAR_RSI = 15
BEAR_RSI_high = 50
BEAR_RSI_low = 20

# ADX
ADX = 3
ADX_high = 70
ADX_low = 50


Please note that this doesn't use a TOML-file so you would need to change the params directly in the script or write an own TOML-file and remove the TEMP-parameters within the script. Do also note that this is merely a test and thus some parts of the script is less ... beautiful.


Attached Files
.txt   RSI_BULL_BEAR_ADX.js.txt (Size: 5 KB / Downloads: 176)
.txt   RSI_BULL_BEAR_ADX.toml.txt (Size: 203 bytes / Downloads: 126)
  Reply


Messages In This Thread
Werkkrew Stoploss - by susitronix - 02-02-2018, 09:39 PM
Removed post - by susitronix - 02-03-2018, 06:49 PM
RE: [SHARE] Simple RSI BULL/BEAR strategy - by tommiehansen - 02-08-2018, 03:05 AM
@Gryphon Confirmation - by mvangoor - 03-22-2019, 11:59 PM
for 3 months - by ankasem - 02-18-2018, 05:30 PM

Forum Jump:


Users browsing this thread: