RSI 移動平均 トレイリングストップ戦略

作者: リン・ハーンチャオチャン, 日時: 2023-09-13 14:26:43
タグ:

この戦略は,RSIと移動平均を組み合わせて,トレンドバイアスを示し,リスク管理のためにトラッキングストップを追加します.適応的な出口でトレンドをフォローすることを目指します.

戦略論理:

  1. RSIを計算すると,買い過ぎ/売過ぎのレベルを判断します. RSIが50を超えると上昇傾向がわかります.

  2. 黄金十字は牛の傾向を示しています

  3. RSIの上昇も 長期入札の兆候です

  4. 入力後,ストップ・ロスを設定し 利益ラインを押します

  5. 価格の下のストップ損失トレイル,上の利益トレイルを取ります.

  6. 価格が止まるか,利益を得るときに退場します.

利点:

  1. RSIは上下を追わない

  2. 移動平均はトレンドの方向性を特定します 組み合わせは正確性を向上させます

  3. トレーリングストップ/利益は価格に動的に調整されます

リスク:

  1. RSIとMAsは,変動市場において誤った信号に易い.

  2. 後ろのストップ幅は慎重に校正する必要があります. 幅が幅も狭すぎると問題です.

  3. 損失の大きさを制限できず,大きな損失を伴う取引のリスクがあります.

概要すると,この戦略は,RSIとMAを組み合わせて,リスク管理のためにトレーリングストップを使用します. 堅牢な最適化とリスク制御により,良い結果を達成することができます.


/*backtest
start: 2022-09-06 00:00:00
end: 2023-09-12 00:00:00
period: 4d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("RSI and MA Strategy with Trailing Stop Loss and Take Profit",
         overlay=true,
         initial_capital=1000,
         process_orders_on_close=true,
         default_qty_type=strategy.percent_of_equity,
         default_qty_value=100,
         commission_type=strategy.commission.percent,
         commission_value=0.1)

showDate = input(defval=true, title='Show Date Range')
timePeriod = time >= timestamp(syminfo.timezone, 2022, 1, 1, 0, 0)
notInTrade = strategy.position_size <= 0

//==================================Buy Conditions============================================

//RSI
length = input(14)
rsi = ta.rsi(close, length)
buyCondition1 = rsi > 50

//MA
SMA9 = ta.sma(close, 9)
SMA50 = ta.sma(close, 50)
SMA100 = ta.sma(close, 100)
plot(SMA9, color = color.green)
plot(SMA50, color = color.orange)
plot(SMA100, color = color.blue)
buyCondition2 = SMA9 > SMA50//ta.crossover(SMA9, SMA100)

//RSI Increase
increase = 5
buyCondition3 = (rsi > rsi[1] + increase)


if (buyCondition1 and buyCondition2 and buyCondition3 and timePeriod) //and buyCondition
    strategy.entry("Long", strategy.long)

//==================================Sell Conditions============================================

//Trailing Stop Loss and Take Profit
longTrailPerc = input.float(title='Trail Long Loss (%)', minval=0.0, step=0.1, defval=2) * 0.01
shortTrailPerc = input.float(title='Trail Short Loss (%)', minval=0.0, step=0.1, defval=1) * 0.01

longStopPrice = 0.0
shortStopPrice = 0.0

longStopPrice := if strategy.position_size > 0
    stopValue = close * (1 - longTrailPerc)
    math.max(stopValue, longStopPrice[1])
else
    0

shortStopPrice := if strategy.position_size < 0
    stopValue = close * (1 + shortTrailPerc)
    math.min(stopValue, shortStopPrice[1])
else
    999999


strategy.exit(id="Exit", stop = longStopPrice, limit = shortStopPrice)

もっと