トレンドトラッキング 移動平均RSI戦略

作者: リン・ハーンチャオチャン,日付: 2023年11月23日 17:13:06
タグ:

img

概要

トレンドトラッキング移動平均RSI戦略は,トレンド分析と過買い過売指標の両方を利用する自動化された株式取引戦略である.この戦略は,市場のトレンド方向性を決定するために単純な移動平均を採用し,相対強度指数 (RSI) 指標を組み合わせ,トレンド判断と追跡を実現し,取引信号を生成する.

戦略の論理

戦略は主に3つの部分で構成されています.

  1. トレンド判断: 200日間のシンプル・ムービング・平均値で長期トレンドと,30日間のシンプル・ムービング・平均値と50日間の短期トレンドを計算する.短期移動平均値が長期平均値を超えると,それは上昇信号であり,下を横切ると,それは低迷信号であり,長期および短期市場のトレンドを決定する.

  2. 過剰購入・過売分析: 14日間のRSI指標を計算する.80を超えるRSIは過買いゾーンで,20未満は過売ゾーンである.RSI指標が過買いゾーンから下落するか過売ゾーンから上昇するときに取引シグナルが生成される.

  3. 入口と出口: 過買いまたは過売りのシグナルが特定された場合,傾向分析と一致する方向性であれば,ロング/ショートポジションが開かれます.短期および長期移動平均値が黄金色のクロスを持つ場合,トレンドが逆転し,既存のポジションが閉鎖されると判断されます.

この戦略によって,価格が逆転するときに,比較的優れた引き上げ制御を備えたトレンド分析を組み込むことで,騒々しい取引をフィルタリングしながら,タイミングで市場に参入することが可能になります.

利点分析

この戦略には以下の利点があります.

  1. トレンド分析と過剰購入・過剰販売の指標を組み合わせ 騒音をフィルタリングし 市場の転換を特定します
  2. より正確な判断をするために 長期的・短期的な時間枠の両方の傾向を考慮します
  3. 移動平均値をストップ・ロスの方法として使って,ストップ・ロスのポイントは市場の変動に基づいて設定できます.
  4. 厳格な入場条件は 偽の脱出を効果的に防ぐのに役立ちます

リスク と 解決策

この戦略にはいくつかのリスクもあります:

  1. 市場が長期間にわたって範囲内にとどまる場合,頻繁な無意味な取引が起こり得る.不要な取引を避けるために追加のフィルターを追加することができます.
  2. 遅延リスクもあります 移動平均周期パラメータを短縮すれば 軽減できます
  3. RSI信号は株式や市場によって影響を受けます.有効性を判断するには,キャンドルスタイルのパターンのようなより多くの要因を組み合わせなければなりません.

オプティマイゼーションの方向性

この戦略は,次の側面においてさらに最適化することができる.

  1. 音量やキャンドルスタイクパターンのような フィルターを追加して 信号の質をさらに改善します
  2. 移動平均値とRSIサイクルのパラメータを最適化し,異なる株の特徴に合わせる
  3. 動的移動平均値を構築して 市場変動とリスクに対する意欲に基づいて パラメータを自動的に調整します
  4. 機械学習のような より高度な技術を使って より正確な市場動向を 決定します

概要

一般的には,トレンドトラッキング・ムービング・平均RSI戦略は,トレンド分析と過買い過売指標を組み合わせることで,市場騒音を一定程度フィルタリングし,取引シグナルをより正確かつ有効にする非常に実践的な戦略のアイデアです.最適化ツールとパラメータが継続的に強化されるにつれて,この戦略は安定して収益性の高い長期取引システムになることができます.


/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mattehalen

// INPUT per TIMEFRAME
// 5min     = Legnth = 9, Source = ohlc4,MaxLoss = 1000 TrendMA = 200, ShortMA = 4, LongMA = 10
// 30min    = Legnth = 7, Source = ohlc4,MaxLoss = 1000 TrendMA = 200, ShortMA = 10, LongMA = 20

strategy("Mathias & Christer Timeframe RSI", shorttitle="M&C_RSI",overlay=true, process_orders_on_close = true, default_qty_type =  strategy.percent_of_equity, default_qty_value = 100)
len = input(9, title="Length", type=input.integer)
src = input(ohlc4, title="Source", type=input.source)
//show4h = input(true, title="show 4h", type=input.bool)
maxLoss = input(3000)

rsiCurrent = rsi(src, len)
//rsi4h = security(syminfo.ticker, "240", rsi(src, len))
rsi4h   = rsi(src, len)

//--------------------------------------------------
//MA
trendMAInput = input(200, title="trendMA", type=input.integer)
shortMAInput = input(30, title="shortMA", type=input.integer)
longMAInput = input(50, title="longMA", type=input.integer)

trendMA = ema(close,trendMAInput)
shortMA = ema(close,shortMAInput)
longMA  = ema(close,longMAInput)
plot(trendMA, color=color.black, linewidth=5)
plot(shortMA, color=color.red, linewidth=2)
plot(longMA, color=color.green, linewidth=2)
bgcolor(crossunder(shortMA,longMA) ? color.black : na, transp=10)

//--------------------------------------------------
//RSI
BuySignalBarssince = barssince(rsi4h[1]<rsi4h[0] and rsi4h[1]<20)
BuySignal       = (rsi4h[1]<rsi4h[0] and rsi4h[1]<20 and BuySignalBarssince[1]>10)
BuySignalOut   = crossunder(longMA[1],shortMA[1])
bgcolor(BuySignal ? color.green : na, transp=70)
bgcolor(BuySignalOut ? color.green : na, transp=10)



SellSignalBarssince = barssince(rsi4h[1]>rsi4h[0] and rsi4h[1]>80)
SellSignal      = (rsi4h[1]>rsi4h[0] and rsi4h[1]>80 and SellSignalBarssince[1]>10)
SellSignalOut   = crossunder(shortMA[1],longMA[1])
bgcolor(SellSignal ? color.red : na, transp=70)
bgcolor(SellSignalOut ? color.red : na, transp=10)


if BuySignal
    strategy.close("short", comment = "Exit short")
    strategy.entry("long", true)
    strategy.exit("Max Loss", "long", loss = maxLoss)

if BuySignalOut
    strategy.close("long", comment = "Exit Long")
if SellSignal
    // Enter trade and issue exit order on max loss.
    strategy.close("long", comment = "Exit Long")
    strategy.entry("short", false)
    strategy.exit("Max Loss", "short", loss = maxLoss)
if SellSignalOut
    // Force trade exit.
    strategy.close("short", comment = "Exit short")
    
//--------------------------------------------------
//ATR
MyAtr = atr(10)
AtrFactor = 10
mySLBuy  = close[BuySignalBarssince]
mySLSell = close[SellSignalBarssince]

plotchar(BuySignal, "BuySignal", "⬆", location.belowbar, color.lime,size =size.huge )
plotchar(BuySignalOut, "BuySignalOut", "█", location.belowbar, color.lime,size =size.small)
plotchar(SellSignal, "SellSignal", "⬇", location.abovebar ,color.red,size =size.huge)
plotchar(SellSignalOut, "SellSignalOut", "█", location.abovebar, color.red,size =size.small)




もっと