ストカスティックモメントムインデックスとRSIベースの量子取引戦略

作者: リン・ハーンチャオチャン, 日付: 2023-12-12 15:20:29
タグ:

img

概要

この戦略は主に2つの指標 - ストカスティックモメントインデックス (SMI) と相対力インデックス (RSI) をベースにしている.また,色フィルターとキャンドルボディフィルターを補助判断条件として組み込む.この戦略は,フィルター条件と組み合わせたSMIとRSIからの買い売り信号に基づいて取引シグナルを生成する.この戦略は,市場で短期間の取引機会を効果的に発見することができます.

戦略の論理

この戦略は,判断のためにSMIとRSIインジケーターに依存する.SMIは主に株が過剰購入または過剰販売されているかどうかを判断し,RSIは株の相対的な強さを決定する.両方のインジケーターが同時に購入信号を与えると,購入アクションが起動する.具体的な論理は以下のとおりである:

  1. SMI が過売れ (下限以下) になった場合,購入信号とみなされます.
  2. RSIが値を下回ると,それは買い信号とみなされます.
  3. SMI の過売れと RSI の相応値を下回る両方が発生すると,購入信号が発信されます.
  4. 販売信号の論理は類似しています

また,この戦略には二重シグナルモードがあります.このモードでは,SMIとRSIの両方のシグナルが任意の取引を誘発します.これは誤ったシグナルを効果的に減らすことができます.

さらに,カラーフィルターとキャンドルボディフィルターが組み込まれています.これらのフィルターは比較的大きなキャンドルボディを必要とし,最後のキャンドルは開くよりも高い値で閉じる必要があります.これは,偽のブレイクをさらに回避することができます.

利点

  1. SMI を過買い/過売りと RSI を相対強さで利用する.二重確認は誤った信号を減らすことができます.
  2. 二重信号モードは,非効率な取引を大幅に減らすことができます
  3. 色や体フィルターは 偽のブレイクを効果的にフィルタリングすることができます
  4. 戦略の論理はシンプルで清潔です
  5. ほとんどのパラメータはカスタマイズできます.

リスク と 最適化

  1. SMI と RSI は単独で使用すると,より多くの誤った信号を生む可能性があります.注意深く検査する必要があります.
  2. 二重信号モードでは,パラメータが正しく設定されていない場合,良い取引機会が逃れることがあります.
  3. 戦略の収益性を異なる周期的なパラメータでテストし,最適なパラメータの組み合わせを見つけることができる
  4. シミュレーションやバックテストを通じて 限界パラメータを評価できる
  5. 戦略を最適化するためにより多くのフィルターを組み込むことを検討することができます

概要

この戦略は,SMIとRSIインジケーターの両方の信号を統合し,ダブル確認を通じて取引オーダーを生成する. 偽のブレイクアウトをフィルタリングするためにカラーフィルターとキャンドルボディフィルターも実装されている. 戦略はシンプルでクリーンな論理フローがあり,ほとんどのパラメータはカスタマイズ可能である. 適切なパラメータを調整することでより良いリターンを達成することができる.


/*backtest
start: 2023-12-04 00:00:00
end: 2023-12-06 19:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2018

//@version=2
strategy(title = "Noro's Stochastic Strategy v1.3", shorttitle = "Stochastic str 1.3", overlay = false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)

//Settings 
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
usemar = input(false, defval = false, title = "Use Martingale")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Capital, %")
usesmi = input(true, defval = true, title = "Use SMI Strategy")
usersi = input(true, defval = true, title = "Use RSI Strategy")
usecol = input(true, defval = true, title = "Use Color-Filter")
usebod = input(true, defval = true, title = "Use Body-Filter")
a = input(2, defval = 2, minval = 2, maxval = 50, title = "SMI Percent K Length")
b = input(2, defval = 2, minval = 2, maxval = 50, title = "SMI Percent D Length")
limitsmi = input(50, defval = 50, minval = 1, maxval = 100, title = "SMI Limit")
periodrsi = input(2, defval = 2, minval = 2, maxval = 50, title = "RSI Period")
limitrsi = input(10, defval = 10, minval = 1, maxval = 50, title = "RSI Limit")
double = input(false, defval = false, title = "SMI+RSI Mode")
showbg = input(false, defval = false, title = "Show background")
fromyear = input(2018, defval = 2018, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//Fast RSI
fastup = rma(max(change(close), 0), periodrsi)
fastdown = rma(-min(change(close), 0), periodrsi)
fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))

//Stochastic Momentum Index
ll = lowest (low, a)
hh = highest (high, a)
diff = hh - ll
rdiff = close - (hh+ll)/2
//avgrel = ema(ema(rdiff,b),b)
//avgdiff = ema(ema(diff,b),b)
avgrel = sma(sma(rdiff,b),b)
avgdiff = sma(sma(diff,b),b)
SMI = avgdiff != 0 ? (avgrel/(avgdiff/2)*100) : 0
SMIsignal = ema(SMI,b)

//Lines
plot(SMI, color = blue, linewidth = 3, title = "Stochastic Momentum Index")
plot(SMIsignal, color = red, linewidth = 3, title = "SMI Signal Line")
plot(limitsmi, color = black, title = "Over Bought")
plot(-1 * limitsmi, color = black, title = "Over Sold")
plot(0, color = blue, title = "Zero Line")

//Color-Filter
gb = close > open or usecol == false
rb = close < open or usecol == false

//Body Filter
nbody = abs(close - open)
abody = sma(nbody, 10)
body = nbody > abody / 3 or usebod == false

//Signals
up1 = SMI < -1 * limitsmi and rb and body and usesmi
dn1 = SMI > limitsmi and gb and body and usesmi
up2 = fastrsi < limitrsi and rb and body and usersi
dn2 = fastrsi > 100 - limitrsi and gb and body and usersi
exit = ((strategy.position_size > 0 and close > open) or (strategy.position_size < 0 and close < open)) and body

//Background
redb = (SMI > limitsmi and usesmi) or (fastrsi > 100 - limitrsi and usersi)
limeb = (SMI < -1 * limitsmi and usesmi) or (fastrsi < limitrsi and usersi)
col = showbg == false ? na : redb ? red : limeb ? lime : na
bgcolor(col, transp = 50)

//Trading
profit = exit ? ((strategy.position_size > 0 and close > strategy.position_avg_price) or (strategy.position_size < 0 and close < strategy.position_avg_price)) ? 1 : -1 : profit[1]
mult = usemar ? exit ? profit == -1 ? mult[1] * 2 : 1 : mult[1] : 1
lot = strategy.position_size == 0 ? strategy.equity / close * capital / 100 * mult : lot[1]

signalup = ((up1 or up2) and double == false) or (up1 and up2 and double)
if signalup
    if strategy.position_size < 0
        strategy.close_all()
        
    strategy.entry("long", strategy.long, needlong == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

signaldn = ((dn1 or dn2) and double == false) or (dn1 and dn2 and double)
if signaldn
    if strategy.position_size > 0
        strategy.close_all()
        
    strategy.entry("Short", strategy.short, needshort == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    
if time > timestamp(toyear, tomonth, today, 23, 59) or exit
    strategy.close_all()

もっと