EMAとストキャスティクスRSIに基づく複数期間のトレンドフォロー取引戦略


作成日: 2024-03-08 17:32:38 最終変更日: 2024-03-08 17:32:38
コピー: 3 クリック数: 772
1
フォロー
1617
フォロワー

EMAとストキャスティクスRSIに基づく複数期間のトレンドフォロー取引戦略

戦略概要

この策略は”EMAとランダムなRSIに基づく多周期的なトレンド追跡トレーディング戦略”と呼ばれ,指数移動平均 ((EMA) とランダムなRSIの2つの異なる周期を利用して,市場の中長期のトレンドを捕捉する.戦略の核心思想は,EMAの交差によってトレンドの方向を判断し,同時にランダムなRSIをトレンド確認と逆転の警告信号として組み合わせて,トレンドの形成の初期にポジションを確立し,トレンドの終期に平仓する.

戦略原則

  1. 速いEMAと遅いEMAを計算する.速いEMAのデフォルトパラメータは12で,遅いEMAのデフォルトパラメータは25で,実際のアプリケーションでは,市場の特徴と取引頻度に応じて調整することができる.

  2. 余空傾向を判断する:

  • 高速EMAが低速EMAを横切ると,多読信号が生成される
  • 高速EMAが低速EMAの下を通過すると空見信号が生成される.
  1. トレンド確認:看多/看空信号が現れた後,連続して2本の看多/看空K線が現れてトレンドが形成されたことを確認する.これは偽信号をフィルタリングするのに役立ちます.

  2. ランダムなRSIを補助判断として使用します.

  • ランダムなRSI %K値が%D値に突入し,%K値が20以下であるとき,超売りシグナルが生み出され,上昇の逆転の可能性を示唆します.
  • ランダムなRSI %K値が%D値を下回り,%K値が80を超えると,超買いシグナルが生み出され,下落が逆転する可能性を示唆する
  1. 取引戦略:
  • EMAが看板信号を発し,ランダムなRSIが超買い領域にないとき,ポジションを開きます.
  • EMAが空売り信号を発し,ランダムなRSIが超売りゾーンにないとき,空売り

戦略的優位性

  1. 同時に2つの異なる周期のEMAを使用することで,トレンドの捉え方の感度と信頼性をより良くバランスさせることができます. 分析は,12/25周期のEMA組み合わせが中長期のトレンドを把握するのに優れていることを示しています.

  2. トレンド確認のメカニズムは,ほとんどの偽信号を効果的にフィルターし,戦略の勝利率を高めます.

  3. ランダムなRSIは,トレンドの初期にトレンドの強さを判断するのに役立つ補助的な判断として,トレンドの後半に可能になるトレンドの逆転を予期させるのに役立ちます.

  4. 戦略の論理はシンプルで,パラメータは少なく,容易に理解し,実行し,多種多様な市場と品種に適用されます.

リスク分析

  1. EMAは遅れの指標であり,トレンドの逆転の初期に大きな滑り場が発生する可能性があります.

  2. トレンド型戦略は,震動する市で一般的である.この戦略には,震動する市に対する専門的な判断が欠けている.

  3. ランダムなRSIは,市場が激しく波動する時に誤って判断の質に影響を与える可能性があります.

  4. 固定パラメータは,すべての市場の状況に適応できない場合があり,市場の特徴の動向に応じて調整する必要があります.

最適化の方向

  1. ATRなどの波動率指標を導入し,波動率の動向に応じてEMAパラメータを調整し,異なる市場リズムに対応する.

  2. ブリン帯の開口方向など,振動市場の判断を高め,振動市場の頻繁な取引を避ける.

  3. ランダムなRSIに基づいて,取引量変化などのより多くの補助判断を組み込むことで,信号の信頼性を向上させる.

  4. 市場関連性を考慮し,多種連結信号を導入し,システムのリスク抵抗性を強化する.

要約する

この戦略は,EMAとランダムRSIの優位性を充分利用し,トレンド追跡と動力反転に基づく中長期取引戦略を形成している.均線交差捕捉のトレンド,ランダムRSIのトレンド強度確認と警告反転,トレンド確認メカニズムによる信号品質の向上,この3つが有機的に結合し,シンプルで効果的な定量化取引戦略の枠組みを形成している.主な優位性は,論理の簡潔さ,パラメータの数が少ない,実行の難しさが低い,適用範囲が広いことである.同時に,戦略は,動態パラメータの最適化,より多くの補助判断を導入し,商品の結合の動きなどの側面を構築し,将来的に深め,完善することができる.全体的に言えば,広範囲の最適化と景観の適用を持つ前向きの量化取引戦略である.

ストラテジーソースコード
/*backtest
start: 2023-03-02 00:00:00
end: 2024-03-07 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('[Jacky] Trader XO Macro Trend Scanner', overlay=true)

// Variables
var ok = 0
var countBuy = 0
var countSell = 0
src = input(close, title='OHLC Type')
i_fastEMA = input(12, title='Fast EMA')
i_slowEMA = input(25, title='Slow EMA')
i_defEMA = input(25, title='Consolidated EMA')

// Allow the option to show single or double EMA
i_bothEMAs = input(title='Show Both EMAs', defval=true)

// Define EMAs
v_fastEMA = ta.ema(src, i_fastEMA)
v_slowEMA = ta.ema(src, i_slowEMA)
v_biasEMA = ta.ema(src, i_defEMA)

// Color the EMAs
emaColor = v_fastEMA > v_slowEMA ? color.green : v_fastEMA < v_slowEMA ? color.red : #FF530D

// Plot EMAs
plot(i_bothEMAs ? na : v_biasEMA, color=emaColor, linewidth=3, title='Consolidated EMA')
plot(i_bothEMAs ? v_fastEMA : na, title='Fast EMA', color=emaColor)
plot(i_bothEMAs ? v_slowEMA : na, title='Slow EMA', color=emaColor)

// Colour the bars
buy = v_fastEMA > v_slowEMA
sell = v_fastEMA < v_slowEMA

if buy
    countBuy += 1
    countBuy

if buy
    countSell := 0
    countSell

if sell
    countSell += 1
    countSell

if sell
    countBuy := 0
    countBuy

buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and not buy[1]
sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and not sell[1]

barcolor(buysignal ? color.green : na)
barcolor(sellsignal ? color.red : na)

// Strategy backtest
if (buysignal)
    strategy.entry("Buy", strategy.long)

if (sellsignal)
    strategy.entry("Sell", strategy.short)

// Plot Bull/Bear

plotshape(buysignal, title='Bull', text='Bull', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.black, 0), size=size.tiny)
plotshape(sellsignal, title='Bear', text='Bear', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.black, 0), size=size.tiny)

bull = countBuy > 1
bear = countSell > 1

barcolor(bull ? color.green : na)
barcolor(bear ? color.red : na)

// Set Alerts

alertcondition(ta.crossover(v_fastEMA, v_slowEMA), title='Bullish EMA Cross', message='Bullish EMA crossover')
alertcondition(ta.crossunder(v_fastEMA, v_slowEMA), title='Bearish EMA Cross', message='Bearish EMA Crossover')

// Stoch RSI code

smoothK = input.int(3, 'K', minval=1)
smoothD = input.int(3, 'D', minval=1)
lengthRSI = input.int(14, 'RSI Length', minval=1)
lengthStoch = input.int(14, 'Stochastic Length', minval=1)

rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

bandno0 = input.int(80, minval=1, title='Upper Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')
bandno2 = input.int(50, minval=1, title='Middle Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')
bandno1 = input.int(20, minval=1, title='Lower Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')

// Alerts

crossoverAlertBgColourMidOnOff = input.bool(title='Crossover Alert Background Colour (Middle Level) [ON/OFF]', group='Crossover Alerts', defval=false)
crossoverAlertBgColourOBOSOnOff = input.bool(title='Crossover Alert Background Colour (OB/OS Level) [ON/OFF]', group='Crossover Alerts', defval=false)

crossoverAlertBgColourGreaterThanOnOff = input.bool(title='Crossover Alert >input [ON/OFF]', group='Crossover Alerts', defval=false)
crossoverAlertBgColourLessThanOnOff = input.bool(title='Crossover Alert <input [ON/OFF]', group='Crossover Alerts', defval=false)

maTypeChoice = input.string('EMA', title='MA Type', group='Moving Average', options=['EMA', 'WMA', 'SMA', 'None'])
maSrc = input.source(close, title='MA Source', group='Moving Average')
maLen = input.int(200, minval=1, title='MA Length', group='Moving Average')

maValue = if maTypeChoice == 'EMA'
    ta.ema(maSrc, maLen)
else if maTypeChoice == 'WMA'
    ta.wma(maSrc, maLen)
else if maTypeChoice == 'SMA'
    ta.sma(maSrc, maLen)
else
    0

crossupCHECK = maTypeChoice == 'None' or open > maValue and maTypeChoice != 'None'
crossdownCHECK = maTypeChoice == 'None' or open < maValue and maTypeChoice != 'None'

crossupalert = crossupCHECK and ta.crossover(k, d) and (k < bandno2 or d < bandno2)
crossdownalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno2 or d > bandno2)
crossupOSalert = crossupCHECK and ta.crossover(k, d) and (k < bandno1 or d < bandno1)
crossdownOBalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno0 or d > bandno0)

aboveBandalert = ta.crossunder(k, bandno0)
belowBandalert = ta.crossover(k, bandno1)

bgcolor(color=crossupalert and crossoverAlertBgColourMidOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert Background Colour (Middle Level)', transp=70)
bgcolor(color=crossupOSalert and crossoverAlertBgColourOBOSOnOff ? #fbc02d : crossdownOBalert and crossoverAlertBgColourOBOSOnOff ? #000000 : na, title='Crossover Alert Background Colour (OB/OS Level)', transp=70)

bgcolor(color=aboveBandalert and crossoverAlertBgColourGreaterThanOnOff ? #ff0014 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K > Upper level', transp=70)
bgcolor(color=belowBandalert and crossoverAlertBgColourLessThanOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K < Lower level', transp=70)

alertcondition(crossupalert or crossdownalert, title='Stoch RSI Crossover', message='STOCH RSI CROSSOVER')