移動平均相対強度指数戦略

作者: リン・ハーンチャオチャン, 日付: 2023-11-28 14:07:46
タグ:

img

概要

移動平均相対強度指数戦略は,移動平均線と相対強度指数 (RSI) を両方を取引信号として利用して市場動向の機会を把握する定量的な取引戦略である.この戦略は,価格移動平均線とRSI指数の値を比較して,市場の逆転機会を把握するために取引信号を生成する.

戦略の論理

この戦略は主に2つの指標に基づいています.

  1. シンプル・ムービング・アベア (SMA): 価格の平均傾向を反映する.
  2. 相対強度指数 (RSI): 価格パフォーマンスの強度または弱さを反映する.

戦略の基本的な論理は

RSI指標線が移動平均線より低いとき,それは過売り領域にあり,株が過大評価されていることを示し,購入信号を生成する.RSI線が移動平均線よりも高いとき,それは過大購入領域にあり,株が過大評価されていることを示し,売り信号を生成する.

言い換えれば,移動平均線は,ある程度株のフェアバリューを反映し,RSIインジケーターは,現在の価格の強度または弱さを表しています.RSIが移動平均線から逸脱すると,逆転の機会を意味します.

具体的には,この戦略は,次のステップを通じて取引信号を生成します.

  1. 株価のRSI値と単純な移動平均を計算します.
  2. RSI値と移動平均線の関係を比較する.
  3. RSI線が移動平均線を横切ると売り信号が生成されます.
  4. RSI線が移動平均線を下回るときに買い信号が発信されます.
  5. リスクをコントロールするためにストップ・ロストとトラッキング・ストップを設定します

戦略 の 利点

移動平均値の傾向判断とRSIの過買い/過売指標を組み合わせることで,この戦略は異なる指標の強みを活用して市場の転換点を効果的に決定することができます.

主な利点は以下の通りです.

  1. 移動平均値は価格動向を効果的に示すことができます
  2. RSIは過買い/過売状態を反映する可能性があります.
  3. 二重指標の組み合わせにより,市場の転換点を正確に特定できます.
  4. ストップ・ロスはリスクを制御するために使えます

戦略 の リスク

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

  1. インディケーターから誤った信号が発信され,不必要な損失を引き起こす可能性があります.
  2. ストップ・ロスは 激しい市場変動の際に 引き起こすこともあり 大きな損失につながる.
  3. 間違ったパラメータ設定も 戦略のパフォーマンスに影響を与えます

リスク管理のために,最適化は次の方法で行えます.

  1. 移動平均値とRSIのパラメータを調整し,インジケーター信号をより信頼できるものにします.
  2. 停止損失を適度に広げて,頻繁に起動しないようにする.
  3. ストップ損失をより柔軟にするため ダイナミック・トラッキング・ストップ・ロスを採用する.

戦略の最適化のための方向性

さらに最適化方向は以下の通りである.

  1. 最適なパラメータを見つけるために 異なるパラメータの組み合わせを タイムフレームでテストします
  2. シグナル信頼性を向上させるため,フィルターの音量などの他の指標を追加します.
  3. ストップ・ロスの戦略を最適化してストップ・ロスを よりダイナミックで合理的にします
  4. 適応性パラメータ最適化のためのディープラーニングモデルを組み込む.
  5. ポジションサイズモジュールを追加し,市場の状況に基づいてポジションを動的に調整します.

パラメータの最適化,指標の最適化,リスク管理の最適化などを通じて この戦略の安定性と収益性を継続的に改善することができます.

結論

移動平均RSI戦略は,価格動向と過買い/過売分析の両方を活用して,市場のターニングポイントを効果的に特定し,逆転機会を把握する.このシンプルで実践的な戦略には制御可能なリスクがあり,定量的な取引に有用である.さらなる最適化によりさらに良い結果が得られる.


/*backtest
start: 2023-11-20 00:00:00
end: 2023-11-24 06:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2

strategy(title = "RSI versus SMA", shorttitle = "RSI vs SMA", overlay = false, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, currency = currency.GBP)

// Revision:        1
// Author:          @JayRogers
//
// *** USE AT YOUR OWN RISK ***
// - Nothing is perfect, and all decisions by you are on your own head. And stuff.
//
// Description:
//  - It's RSI versus a Simple Moving Average.. Not sure it really needs much more description.
//  - Should not repaint - Automatically offsets by 1 bar if anything other than "open" selected as RSI source.

// === INPUTS ===
// rsi
rsiSource   = input(defval = open, title = "RSI Source")
rsiLength   = input(defval = 8, title = "RSI Length", minval = 1)
// sma
maLength    = input(defval = 34, title = "MA Period", minval = 1)
// invert trade direction
tradeInvert = input(defval = false, title = "Invert Trade Direction?")
// risk management
useStop     = input(defval = false, title = "Use Initial Stop Loss?")
slPoints    = input(defval = 25, title = "Initial Stop Loss Points", minval = 1)
useTS       = input(defval = true, title = "Use Trailing Stop?")
tslPoints   = input(defval = 120, title = "Trail Points", minval = 1)
useTSO      = input(defval = false, title = "Use Offset For Trailing Stop?")
tslOffset   = input(defval = 20, title = "Trail Offset Points", minval = 1)
// === /INPUTS ===

// === BASE FUNCTIONS ===
// delay for direction change actions
switchDelay(exp, len) =>
    average = len >= 2 ? sum(exp, len) / len : exp[1]
    up      = exp > average
    down    = exp < average
    state   = up ? true : down ? false : up[1]
// === /BASE FUNCTIONS ===

// === SERIES and VAR ===
// rsi
shunt = rsiSource == open ? 0 : 1
rsiUp = rma(max(change(rsiSource[shunt]), 0), rsiLength)
rsiDown = rma(-min(change(rsiSource[shunt]), 0), rsiLength)
rsi = (rsiDown == 0 ? 100 : rsiUp == 0 ? 0 : 100 - (100 / (1 + rsiUp / rsiDown))) - 50 // shifted 50 points to make 0 median
// sma of rsi
rsiMa   = sma(rsi, maLength)
// self explanatory..
tradeDirection = tradeInvert ? 0 <= rsiMa ? true : false : 0 >= rsiMa ? true : false
// === /SERIES ===

// === PLOTTING ===
barcolor(color = tradeDirection ? green : red, title = "Bar Colours")
// hlines
medianLine  = hline(0, title = 'Median', color = #996600,  linewidth = 1)
limitUp     = hline(25, title = 'Limit Up', color = silver,  linewidth = 1)
limitDown   = hline(-25, title = 'Limit Down', color = silver,  linewidth = 1)
// rsi and ma
rsiLine     = plot(rsi, title = 'RSI', color = purple, linewidth = 2, style = line, transp = 50)
areaLine    = plot(rsiMa, title = 'Area MA', color = silver, linewidth = 1, style = area, transp = 70)
// === /PLOTTING ===

goLong() => not tradeDirection[1] and tradeDirection
killLong() => tradeDirection[1] and not tradeDirection
strategy.entry(id = "Buy", long = true, when = goLong())
strategy.close(id = "Buy", when = killLong())

goShort() => tradeDirection[1] and not tradeDirection
killShort() => not tradeDirection[1] and tradeDirection
strategy.entry(id = "Sell", long = false, when = goShort())
strategy.close(id = "Sell", when = killShort())

if (useStop)
    strategy.exit("XSL", from_entry = "Buy", loss = slPoints)
    strategy.exit("XSS", from_entry = "Sell", loss = slPoints)
// if we're using the trailing stop
if (useTS and useTSO) // with offset
    strategy.exit("XSL", from_entry = "Buy", trail_points = tslPoints, trail_offset = tslOffset)
    strategy.exit("XSS", from_entry = "Sell", trail_points = tslPoints, trail_offset = tslOffset)
if (useTS and not useTSO) // without offset
    strategy.exit("XSL", from_entry = "Buy", trail_points = tslPoints)
    strategy.exit("XSS", from_entry = "Sell", trail_points = tslPoints)

もっと