簡(jiǎn)易版牛熊判定,短線對(duì)沖交易策略[gekko]

策略介紹

該策略非原創(chuàng),來自github: https://github.com/Saichovsky, 本文不構(gòu)成任何投資建議,僅供參考。

這是一個(gè)基于MA(移動(dòng)平均線)來自動(dòng)改變RSI參數(shù)的短線交易策略,自動(dòng)判斷牛熊。

我把測(cè)試結(jié)果放在前面,希望大家看到后如果覺得收益不是很滿意,就不需要配置該策略文件了,幫大家節(jié)省時(shí)間。 該策略更適合USDT/BTC交易對(duì)。

該策略回測(cè)結(jié)果

  • noop為不做交易的情況下的收益率。系統(tǒng)默認(rèn)策略中,我選擇了RSI, 是因?yàn)樵谝酝鶞y(cè)試中發(fā)現(xiàn)該策略收益更理想一些,而且本文介紹的策略是基于RSI優(yōu)化的。在調(diào)整過程中,Candle Size 10minute也是測(cè)試的最佳時(shí)間間隔。

測(cè)試結(jié)果

參數(shù):
  • Candle Size: 10 minute
  • 回測(cè)時(shí)間段: 2018.01.03-2018.03.03
  • 數(shù)據(jù)來源: 幣安
  • RSI_BULL_BEAR 策略參數(shù)
    *BEAR_RSI = 15
    *BEAR_RSI_high = 50
    *BEAR_RSI_low = 25
收益率統(tǒng)計(jì)
交易對(duì) \策略 noop RSI RSI_BULL_BEAR
USDT/BTC -17.87931% -25.47593% 10.72157%
USDT/ETH 10.72157% -21.74737% -5.33235%
BTC/ADA - -43.44617% -37.35651%
  1. USDT/BTC
    統(tǒng)計(jì)結(jié)果:在該時(shí)間段 完成 41次 買入/賣出操作,使用RSI_BULL_BEAR 該策略收益大概20%左右。
    屏幕快照 2018-03-03 上午9.53.34.png
  1. USDT/ETH
    統(tǒng)計(jì)結(jié)果:在該時(shí)間段 完成 42次 買入/賣出操作,使用RSI_BULL_BEAR 該策略收益大概-15%左右。
    屏幕快照 2018-03-03 上午10.17.02.png
  1. BTC/ADA
    統(tǒng)計(jì)結(jié)果:在該時(shí)間段 完成 42次 買入/賣出操作,使用RSI_BULL_BEAR 該策略收益大概-37%左右。
    btc:ada.png

策略配置

  1. 將如下代碼文件保存在 RSI_BULL_BEAR.js 文件中,放置在路徑gekko/config/strategies 下。
/*
    RSI Bull and Bear
    Use different RSI-strategies depending on a longer trend

    (CC-BY-SA 4.0) Tommie Hansen
    https://creativecommons.org/licenses/by-sa/4.0/
*/

var _ = require ('lodash');
var log = require ('../core/log.js');

// Configuration
var config = require ('../core/util.js').getConfig();
var async = require ('async');

// Let's create our own method
var method = {};


// Prepare everything our method needs
method.init = function () {

   this.name = 'RSI Bull and Bear';

   // Keep state about stuff
   this.trend = {
       direction: 'none',
       duration: 0,
       persisted: false,
       adviced: false
   };

   // How many candles do we need as a base before start giving advice
   this.requiredHistory = config.tradingAdvisor.historySize;

    // add indicators
    this.addTulipIndicator('maSlow', 'sma', { optInTimePeriod: this.settings.SMA_long });
    this.addTulipIndicator('maFast', 'sma', { optInTimePeriod: this.settings.SMA_short });

    this.addTulipIndicator('BULL_RSI', 'rsi', { optInTimePeriod: this.settings.BULL_RSI });
    this.addTulipIndicator('BEAR_RSI', 'rsi', { optInTimePeriod: this.settings.BEAR_RSI });

}

// What happens on every new candle?
method.update = function(candle) {} // do nothing
method.log = function() {} // do nothing

method.check = function (candle)
{
   if( candle.close.length < this.requiredHistory ) { return; } // TODO: still needed?!

    // get all indicators
    let ind = this.tulipIndicators;

    let maSlow = ind.maSlow.result.result,
        maFast = ind.maFast.result.result,
        rsi;


    // define rules
    let goLong = false,
        goShort = false;

    // BEAR TREND
    if( maFast < maSlow )
    {
        log.debug('BEAR Trend');
        rsi = ind.BEAR_RSI.result.result;
        if( rsi > this.settings.BEAR_RSI_high ) goShort = true;
        if( rsi < this.settings.BEAR_RSI_low )  goLong = true;
    }

    // BULL TREND
    else
    {
        log.debug('BULL Trend');
        rsi = ind.BULL_RSI.result.result;
        if( rsi > this.settings.BULL_RSI_high ) goShort = true;
        if( rsi < this.settings.BULL_RSI_low )  goLong = true;
    }

    // LONG
    if( goLong )
    {

        // new trend? (only act on new trends)
        if (this.trend.direction !== 'up')
        {

            // reset the state for the new trend
            this.trend = {
                duration: 0,
                persisted: false,
                direction: 'up',
                adviced: false
            };


            if( !this.trend.adviced )
            {
                this.trend.adviced = true;
                this.advice('long');
            }
            else {
                this.advice();
            }

        }

        this.trend.duration ++;
        log.debug ('Positive since ', this.trend.duration, 'candle (s)');

    }

    // SHORT
    else if( goShort )
    {

        // new trend? (else do things)
        if( this.trend.direction !== 'down' )
        {

            // reset state
            this.trend = {
                duration: 0,
                persisted: false,
                direction: 'down',
                adviced: false
            };

            if( !this.trend.adviced )
            {
                this.trend.adviced = true;
                this.advice ('short');
            }
            else {
                this.advice();
            }

        }

        this.trend.duration ++;
        log.debug ('Negative since ', this.trend.duration, 'candle (s)');

    }

    // default
    else
    {
        //log.debug('No trend');
        this.advice();
    }

} // method.check()

module.exports = method;
  1. 將如下代碼文件保存為 RSI_BULL_BEAR.toml 文件,放在 gekko/config/strategies路徑下
# BEAR
BEAR_RSI = 15
BEAR_RSI_high = 50
BEAR_RSI_low = 25


# BULL/BEAR is defined by the longer SMA trends
# if SHORT over LONG = BULL
# if SHORT under LONG = BEAR
  1. 保存完成后,在gekko路徑下執(zhí)行如下命令(docker方式啟動(dòng))
docker-compose build
HOST=deamon.com PORT=3000 docker-compose up -d   # HOST 需要修改

歡迎大家加入gekko 知識(shí)星球, 在這里你可以得到,關(guān)于gekko環(huán)境搭建問題的解答/查看群主分享的交易機(jī)器人策略/加入gekko策略交流群組,以及獲取更多的關(guān)于gekko使用方面的信息。
沒有任何基礎(chǔ)的小白也可以搭建自己的交易機(jī)器人。


gekko交流
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 策略是Gekko自動(dòng)化交易的核心。他們關(guān)注市場(chǎng)并根據(jù)技術(shù)分析指標(biāo)決定做什么。 默認(rèn)策略介紹 DEMA這個(gè)方法使用(...
    哈哈098833閱讀 1,185評(píng)論 0 1
  • 一、標(biāo)題設(shè)置 代碼: 顯示效果: 一級(jí) 二級(jí) 三級(jí) 四級(jí) 五級(jí) 六級(jí) Headline1 Headline2 二、...
    孞言閱讀 530評(píng)論 0 0
  • “就感受而言,完美的愛就象是色彩中的白色一樣。 許多人以為白色是沒有色彩的。不是的,白色涵括了所 有的色彩。白色是...
    岳曉晴閱讀 200評(píng)論 0 0
  • 十秒鐘短視頻,完成快速變臉,秀出你的彩妝功力吧! 最終效果示例 抖音變臉挑戰(zhàn) 1 抖音變臉挑戰(zhàn) 2 by 熊寶寶 ...
    羊一只_閱讀 2,092評(píng)論 0 0
  • NZYDDXYYDZZMZN.
    十一先生_閱讀 224評(píng)論 0 0

友情鏈接更多精彩內(nèi)容