移動平均に基づくトレンドフォロー戦略


作成日: 2023-10-07 15:04:00 最終変更日: 2023-10-07 15:04:00
コピー: 0 クリック数: 626
1
フォロー
1617
フォロワー

概要

この戦略は,異なる周期の移動平均を計算して,現在のトレンドの方向を識別し,RSI指標と組み合わせて,買入シグナルを発信する.短期移動平均の上部に長期移動平均を穿越すると,トレンドが上昇すると考え,買入操作を行う.短期移動平均の下部に長期移動平均を穿越すると,トレンドが逆転すると考え,売り出し操作を行う.少量の価格変動による偽信号を避けるために,RSI指標と組み合わせて.

戦略原則

  1. 10日,20日,50日,100日,200日の移動平均を計算する.

  2. 14日RSIを計算する.

  3. 10日SMAで50日SMAを突破し,RSIが30以上で,20日SMAが100日SMA以上または100日SMA以上または50日SMA以上または100日SMAと同等であるとき,購入する.

  4. 購入ポイントのストップ・プライスを1で減算したストップ・パーセンテージに設定します.

  5. 販売は,以下の状況にある場合に行われます.

    • 10日SMAの下から50日SMAを突破し,20日SMAより下から閉じる:トレンドは逆転して売り出さ
    • 購入価格の95%以下で閉店: ストップ・ローズで売却
    • 閉店価格がストップ価格を下回った:トレンド追跡ストップ損失売り

この戦略は,移動平均によって市場のトレンド方向を判断し,リスクを制御するためにストップを設定する. RSI指標は,偽の突破をフィルターするために使用される. 短期SMAで長期SMAを突破するときに購入し,トレンドが向上していることを示すときにストップラインを設定し,株を保有するときにリスク制御を行う. トレンドの反転信号が発生したときに株を売却する.

優位分析

  • 移動平均を用いてトレンドの方向を判断し,トレンドの上昇段階を購入することで,波動的な市場を整理する取引を回避できます.
  • 短期的な価格変動に惑わされないように,多周期的な移動平均を使用
  • RSIと組み合わせて偽信号をフィルターします.
  • ストップラインを設定し,単一の損失のリスクをコントロールします.
  • トレンドトラッキングのストップを活用して利益を固定する

リスク分析

  • 移動平均は遅滞しており,価格の逆転の最適なタイミングを逃している可能性があります.
  • ストップ・ロスの設定が緩やかすぎると,単発損失が大きくなる可能性があります.
  • 止損設定が厳しすぎると止損が頻繁になる可能性があります.
  • トレンドトラッキングのストップ・ローズは,早退で多くのお金を失う可能性が高い.

移動平均周期の調整,ストップ・ポイントの調整などの方法によって最適化することができる.また,他の指標と組み合わせて意思決定の正確性を向上させることも考えることができる.

最適化の方向

  • 移動平均の周期を調整し,異なる市場状況に合わせて調整する
  • RSIパラメータを最適化して,超買いと超売りの判断の精度を向上させる
  • 合理的な静的止損位とトレイルストップの幅を異なる品種特性に合わせて設定する
  • 偽信号を避けるために他の指標を追加します.
  • 波動率などの指標の動態に応じてストップポイントを調整できます.
  • 機械学習によりパラメータを自動的に最適化できます.

要約する

この戦略の全体的な考え方は明確で,移動平均を使用してトレンドを判断し,リスクを制御するためにストップを設定する.これは典型的なトレンド追跡戦略である.パラメータの調整と他の判断指標の追加により,戦略の反射と実物表现をさらに改善することができます.しかし,いかなる戦略も完璧ではありません.市場の状況に応じて,リスク管理と連携して,市場の不確実性に応じて継続的に調整および最適化する必要があります.

ストラテジーソースコード
/*backtest
start: 2022-09-30 00:00:00
end: 2023-10-06 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("MA_Script", overlay=true)

// STEP 1:
// Configure trail stop level with input options (optional)
longTrailPerc=input(title="Trail Long Loss (%)", type=input.float, minval=0.0, step=0.05, defval=0.1)

// Configure backtest start date with inputs
startDate=input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)
startMonth=input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)
startYear=input(title="Start Year", type=input.integer, defval=2020, minval=1800, maxval=2100)

// See if this bar's time happened on/after start date
afterStartDate=(time >=timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))

// Calculate Relative Strength Index
rsiValue=rsi(close, 14)

// Calculate moving averages
MA10_Val =sma(close, 10)
//plot(MA10_Val, color=color.yellow, linewidth=1)

MA20_Val =sma(close, 20)
plot(MA20_Val, color=color.green, linewidth=1)

MA50_Val =sma(close, 50)
plot(MA50_Val, color=color.red, linewidth=1)

MA100_Val =sma(close, 100)
plot(MA100_Val, color=color.blue, linewidth=1) 

MA200_Val =sma(close, 200)
plot(MA200_Val, color=color.purple, linewidth=1) 

// Calculate candlestick
C_BodyHi = max(close, open)
C_BodyLo = min(close, open)
C_Body = C_BodyHi - C_BodyLo
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low

// STEP 2:
// Calculate entry trading conditions
buyCondition_1=crossover(MA10_Val, MA50_Val) and (rsiValue > 30) and ((MA20_Val >=  MA100_Val) or (MA50_Val >=  MA100_Val))
avg_price = (close + open)/2

// First Entry
if (afterStartDate)
    strategy.entry(id="Entry_Trade_1", long=true, limit=avg_price, when=buyCondition_1)

plotchar(afterStartDate and crossover(MA10_Val, MA50_Val), textcolor = color.blue, text = 'MA\n')

// Determine trail stop loss prices
longStopPrice=0.0

longStopPrice :=if (strategy.position_size > 0)
    stopValue=C_BodyHi * (1 - longTrailPerc)
    max(stopValue, longStopPrice[1])
else
    0
plot(longStopPrice, color=color.orange, linewidth=1)

bought_1=strategy.position_size[0] > strategy.position_size[1]
entry_Point_1=valuewhen(bought_1, avg_price, 0)

// STEP 3:
// Calculate exit trading conditions
sellCondition_2=crossunder(MA10_Val, MA50_Val) and (close < MA20_Val)
sellCondition_3_temp=valuewhen((C_BodyHi >= entry_Point_1*1.2), 1, 0)
sellCondition_1=(entry_Point_1*0.95 > close) and (sellCondition_3_temp != 1)
sellCondition_3=(sellCondition_3_temp == 1) and (strategy.position_size > 0) and close <= longStopPrice
plotchar((sellCondition_3 == 1) and (strategy.position_size > 0) and close <= longStopPrice, textcolor = color.red, text = 'TS\n', show_last = 11)
plotchar(crossunder(MA10_Val, MA50_Val), textcolor = color.red, text = 'MA\n')

id_val = ""
stop_val = close
condition = false

if sellCondition_1
    id_val := "Exit By Stop Loss At 7%"
    stop_val := entry_Point_1*0.93
    condition := true
else if sellCondition_2
    id_val := "Exit By Take Profit based on MA"
    stop_val := close
    condition := true
else if sellCondition_3
    id_val := "Exit By Trailing Stop"
    stop_val := longStopPrice
    condition := true

// Submit exit orders for trail stop loss price
if (strategy.position_size > 0)
    //strategy.exit(id="Exit By Stop Loss At 7%", from_entry="Entry_Trade_1", stop=entry_Point_1*0.93, when=sellCondition_1)
    //strategy.exit(id="Exit By Take Profit based on MA", from_entry="Entry_Trade_1", stop=close, when=sellCondition_2)
    strategy.exit(id=id_val, from_entry="Entry_Trade_1", stop=stop_val, when=condition)