跳到主要內容

Gekko 交易機器人 - TEMA 策略 (Triple EMA strategy),附帶有安全網機制 (SafetyNet) 來避免在熊市被套牢



這是一個以 EMA (指數移動平均) 決定做多做空的交易策略,但當短期趨勢超過了 EMA 線則會在上方使用一個更長時間的 SMA (簡單移動平均) 作為整個交易系統的安全網 (SafetyNet),在短期的 SMA 超越這個安全網前會避免任何可能被套牢的交易。所以簡單理解的概念就是在市場看多的時候進行交易,而市場下跌時則避免摻入其中,但實際上的運作狀況仍然有待測試。

JS Code :
/*
TEMA
Triple EMA strategy with 'safety net'
---
Uses 1x TEMA to go long/short if short trend is over TEMA.
On top of this it uses a longer SMA as a safety net and simple
stays out of the market if short SMA is under that SMA.
---
The general idea is to buy in good market conditions and simply not
be a part of longer downwards trends.
*/

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

// strategy
var strat = {


/* INIT */
init: function()
{
// base
this.name = 'TEMA';
this.requiredHistory = config.tradingAdvisor.historySize;
this.debug = false; // outputs messages, set to false to increase performance

// add indicators and reset trend
this.resetTrend();
this.addTulipIndicator('maSlow', 'tema', { optInTimePeriod: this.settings.long });
this.addTulipIndicator('maFast', 'sma', { optInTimePeriod: this.settings.short });

// check if long SMA is to be used
if( this.settings.SMA_long > 0 )
{
this.useSafety = true;
this.addTulipIndicator('maSlowest', 'sma', { optInTimePeriod: this.settings.SMA_long });
}

// set startTime to measure execution time @ end()
this.startTime = new Date();

}, // init()



/* RESET TREND */
resetTrend: function()
{
var trend = {
duration: 0,
direction: 'none',
longPos: false,
};

this.trend = trend;

}, // resetTrend()



/* CHECK */
check: function()
{
// do nothing if we don't got enough history
if( this.candle.close.length < this.requiredHistory ) return;

// fetch indicators
let ti = this.tulipIndicators;
let maFast = ti.maFast.result.result,
maSlow = ti.maSlow.result.result;


// check if safety option > 0
if( this.useSafety )
{
let maSlowest = ti.maSlowest.result.result;
if( maSlow < maSlowest )
{
this.short();
return; // quit
}
}

// other rules
if( maFast > maSlow ) { this.long(); }
else if( maFast < maSlow ) { this.short(); }

}, // check()



/* LONG */
long: function()
{
if( this.trend.direction !== 'up' )
{
this.resetTrend();
this.trend.direction = 'up';
this.advice('long');
}

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



/* SHORT */
short: function()
{
if( this.trend.direction !== 'down' )
{
this.resetTrend();
this.trend.direction = 'down';
this.advice('short');
}

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


/* END */
end: function()
{
let seconds = ((new Date()- this.startTime)/1000),
minutes = seconds/60,
str;

minutes < 1 ? str = seconds + ' seconds' : str = minutes + ' minutes';

log.debug('Finished in ' + str);
}

}; // strat{}



/* EXPORT */
module.exports = strat;

Toml Code : 
# Short / Long (EMA/TEMA)
short = 10
long = 80

# Safety (SMA, 0 = disable)
SMA_long = 200


其實安全網本身是可以關掉的,可以測試看看不同的參數和開關的差異。


留言



這個網誌中的熱門文章

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

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

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 可以有這麼多版本、不同語系的官網,畢竟在最原始的官網內也有「漢語」(簡體中文) 的選項,所以其他的國家自己的官網算代理商嗎? 如果真的要說我會比較建議到 英文版的官網 下載,畢竟這種軟體轉了一手又一手,加了什麼都不知道。

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...