跳到主要內容

Gekko 比特幣、加密貨幣交易機器人 Trading Bot - 簡易版 RSI 自動判定 [牛 / 熊] 市、短線對沖交易策略



這是一個基於 MA (移動平均) 線來自動改變 RSI 參數的短線交易策略,目的在於配合不同市場情況適合不同的應對,才能把可能收益最大化。由於這是一個自訂策略 (Custom Strategy) 所以必須要建立獨立的 .js 檔。

JS CODE :

/*
    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;

將以上的 Code 存成 .js 檔再放到 gekko-develop\strategies 底下。



TOML-file :
# SMA Trends
SMA_long = 800
SMA_short = 40

# BULL
BULL_RSI = 10
BULL_RSI_high = 80
BULL_RSI_low = 50

# 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

以上存成同檔名的 .toml 檔放到 gekko-develop\config\strategies 底下。


在 Gekko 的策略裡面就會看到剛剛新增的 RSI_BULL_BEAR 了。

實際跑 2017/11/2 ~ 2018/2/2 數據的結果,這段時間剛好經歷牛、熊市,可以看到策略轉換的不錯,收益甚至來到 67.9%,原作者也有提到這個策略適合短線對沖,最好把 Candle Size 設為 15 分鐘或較短的時間才能達到效果。

翻譯改寫自 : https://forum.gekko.wizb.it/thread-100.html

Gekko 教學 - 免費的比特幣 (Bitcoin)、加密貨幣自動交易機器人 (Trading Bot),支援幣安 Binance、Poloniex、Bitfinex...等交易所
Gekko 中文社群 :



留言



這個網誌中的熱門文章

WinRAR - 繁體中文版、免費版,別再破解了,老牌壓縮軟體直接免費給你用

WinRAR 應該對於所有 Windows 使用者一點都不陌生,可能也是很多人壓縮、解壓縮檔案的首選,舉凡 RAR、ZIP、7-Zip、TAR ...等檔案格式都可以處理,製作自解壓縮 (.EXE) 檔也沒問題,也算是最老牌的解壓縮軟體之一。 WinRAR 官方網站 :  https://www.win-rar.com 繁體中文版 :  https://rar.tw/download.html 永久免費簡體版 :  http://www.winrar.com.cn/download.htm 其實我也不太理解為什麼一個 WinRAR 可以有這麼多版本、不同語系的官網,畢竟在最原始的官網內也有「漢語」(簡體中文) 的選項,所以其他的國家自己的官網算代理商嗎? 如果真的要說我會比較建議到 英文版的官網 下載,畢竟這種軟體轉了一手又一手,加了什麼都不知道。

Linux (Ubuntu) 查詢硬碟容量、剩餘大小指令

在 Ubuntu Desktop 版本或有安裝 GUI 像 Xfce 的 Server 版本當然可以直接從圖形介面查看硬碟容量和已經使用的大小, 但如果是在純 CLI 版本或使用 SSH 連線時呢?那就需要用到指令了。 顯示硬碟容量、已使用、可用大小。 df -h 查詢資料夾所占硬碟的大小。 du -h 查詢檔案大小 ls -l

MinerGate - 一鍵懶人挖礦程式 (CPU+GPU),自動找出最適合的算法和挖礦貨幣 (支援 BTC、ETH、LTC、XMR...等)

MinerGate 自行開發了一個圖形化介面的挖礦程式,對第一次挖礦的新手來說滿友善的,幾乎不需要任何的設定就會自動找出你的硬體最適合的算法和要挖哪種幣,然後也不必急著申請錢包才能挖,Balance 都會先存在 MinerGate 的伺服器上,要領出才需要錢包,你也隨時都可以上官網來看自己的挖礦進度,但必須說這種挖礦方式雖然很方便但只適合輕度玩家,像是你可能電腦還要拿來做別的事就在背後加減挖一點那種, 如果真的要將機子的效能運用最大化還是得去下載 Claymore、ccminer...等專業的挖礦程式。 (4/26) MinerGate 在許多挖礦社群都被反應有收益偏低的問題,懷疑可能是官方收取了超過表定的手續費。目前推薦直接到礦池挖礦,可以參考 0.1% 超低礦池費的 「台灣 Monero 礦池 」。 MinerGate 官方網站 :  https://minergate.com 推薦連結 : https://minergate.com/a/0fd29cc7b4239115347b993e 註冊頁面 :  https://minergate.com/reg 下載頁面 :  https://minergate.com/downloads/gui 挖礦幣種 : Bitcoin、Ethereum、Zcash、Litecoin、Monero...等 分潤方法 : PPLNS fee 1% 到 註冊頁面 註冊完後就可以下載   MinerGate 專用的挖礦程式 。它有分成 GUI miner 和 Console miner,分別是圖形化介面挖礦程式和指令介面的, 我建議就用 GUI 版本就好了,如果要用控制台挖礦不如去用更專業的  Claymore 。 安裝完後輸入剛剛註冊時的 Email 登入,然後就可以開始挖礦了,像我的就自動偵測成挖 Monero (XMR),以及可以針對自己的硬體調整執行緒來試出最好的設置。 也能在 官網的 Dashnoard 查看自己的挖礦進度,挖到的 shares 會需要一段時間確認後才會顯示在 Balance 裡,如果沒有馬上看到進帳也不用擔心。 根據不同的幣種有不一樣的起付額,達到了之後就可以按 With...