跳到主要內容

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


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


留言



這個網誌中的熱門文章

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

圖解架設 Monero (XMR) 礦池教學,所有 CryptoNight 算法的加密貨幣通用礦池 (Mining Pool),趕快架來讓人挖礦!

隨著 GPU 挖礦越來越難回收成本很多人選擇乾脆自己來開礦池讓別人挖,一來你只需要負擔伺服器營運成本 (比挖礦電費少非常多),也不需要購入太昂貴的硬體 (和挖礦設備相比更是天壤之別),那究竟要滿足什麼條件才能開礦池呢?而實際操作又是如何? 這篇將以「門羅幣」 Monero (XMR) 礦池為例來教大家怎麼從無到有架設一個礦池, 而且這是一個  CryptoNight  通用礦池 ,換句話說你也能拿這套來挖 ETN 、 TRTL 、ITNS ...等同樣算法的貨幣,可以說是 CP 值超高的礦池啊! (一個架好的 TRTL 礦池範例)  node-cryptonote-pool 就是一個基於 Node.js 的礦池系統,它能適用於每個 CryptoNote 的加密貨幣 (Bytecoin, Monero, QuazarCoin, HoneyPenny, etc..), 基本上你目前看到的 CryptoNote 礦池大多都是使用這套系統所架設的 ,它不但提供了現成的網頁介面,還能讓使用者隨時查詢挖礦進度,當然這套系統也有不少 Fork 的版本,這次使用的是最原版的作為範例。 node-cryptonote-pool GitHub :  https://github.com/zone117x/node-cryptonote-pool 安裝套件 這次會選擇架設在 Linux ( Ubuntu ) 系統上,如果是使用其它發行版的 Linux 基本上操作也都是一樣的,可能只有少部份的指令需要更改, Windows 的話則多半需要手動到網站上下載相關套件 (Packages) ,使用上比較麻煩一些但理論上也都是可行的。 安裝礦池會需要以下套件, 在 Windows 系統會需要逐一安裝,而 Linux 可以略過這個步驟,等會統一使用指令安裝即可。 比較需要注意的是它要求的是 v0.10+ 的 Node.js 版本 ,建議你就乖乖的裝遠古時代的 v0.10 版畢竟 Node.js 不同版本間的相容性問題很容易報錯。 Node.js v0.10+  Redis key-value store v2.6+  libssl required for the node-multi-hash...