移動平均後続停止戦略

作者: リン・ハーンチャオチャン, 日付: 2023-09-19 21:33:48
タグ:

概要

この戦略は,速いEMAの買いラインが遅いSMAの買いラインを横切ると買い信号を生成し,リスク管理のためにATRダイナミックトレーリングストップを使用する.限られた取引で買いと保持戦略を上回ることを目的としています.

戦略の論理

  1. 速 EMA と 遅 SMA を計算します 速 EMA と 遅 SMA を計算します 速 EMA と 遅 EMA を計算します

  2. 速いEMAと遅いSMAのセールラインを計算します 速いラインがスローラインを下に突破するとセール信号を生成します

  3. リスク管理のために,動的遅延停止として,N日間の平均ATRを係数で掛け合わせる.

  4. バックテスト期間で戦略を開始し,購入・販売を実行します.

  5. 最適値を見つけるために 各株のパラメータを最適化します

この戦略は,リスク管理のために信号のMA交差とATRトレーリングストップの利点を組み合わせます.パラメータ最適化は,正確な取引で購入と保持よりも過剰な収益を目指して,各製品の特徴に適応します.

利点分析

  1. 急速なEMAと遅いSMAのクロスオーバーは,トレンドを特定し,シグナルを生成します.

  2. ATRのストップは市場の変動に基づいて調整され,リスクは効果的に制御されます.

  3. 各株の最適化により 収益性が向上します

  4. シンプルな論理とルールで 実行し検証しやすい

  5. バックテスト機能を完了して 戦略を検証する

  6. 買って持てるよりも 安定した優位性を求めています

リスク分析

  1. 最適化されたパラメータは将来的には機能しない可能性があります.定期的な再最適化が必要かもしれません.

  2. EMAとSMAの交差は誤った信号または遅延信号を生成する可能性があります.

  3. ATRストップが攻撃的すぎると ストップ・ロストの範囲が 緩くなるかもしれません

  4. 低頻度な取引は 良い機会を逃す可能性があります

  5. 貿易コストの影響を考慮する必要があります

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

  1. 異なるパラメータの組み合わせをテストし,最適な値を探します.

  2. 信号フィルタリングのために他の指標を導入してみてください.

  3. ATR 期間を最適化してストップ損失感度を均衡させる.

  4. ストップ・ロスの範囲を緩和する効果を評価する.

  5. 自動パラメータ最適化のための機械学習を考えてみましょう

  6. 貿易頻度の増加による研究効果

概要

この移動平均トレーリングストップ戦略は,シグナルのためのMAクロスオーバーとリスク制御のためのATRストップの強みを組み合わせます.パラメータ最適化は,それぞれの株の特徴に適応します.最適化されたパラメータには保証はありませんが,全体的な論理は簡単で,買いと保持を上回る実用的です.戦略には良いインスピレーションの価値があるため,さらなる改善と検証は価値があります.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
//created by XPloRR 04-03-2018

strategy("XPloRR MA-Trailing-Stop Strategy",overlay=true, initial_capital=1000,default_qty_type=strategy.percent_of_equity,default_qty_value=100)

testStartYear = input(2005, "Start Year")
testStartMonth = input(1, "Start Month")
testStartDay = input(1, "Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2050, "Stop Year")
testStopMonth = input(12, "Stop Month")
testStopDay = input(31, "Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

testPeriodBackground = input(title="Background", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

ema1Period = input(12, "Fast EMA Buy")
sma1Period = input(54, "Slow SMA Buy")
strength1 = input(52, "Minimum Buy Strength")

ema2Period = input(18, "Fast EMA Sell")
sma2Period = input(55, "Slow SMA Sell")
strength2 = input(100, "Minimum Sell Strength")

delta = input(8, "Trailing Stop (#ATR)")

testPeriod() => true

ema1val=ema(close,ema1Period)
sma1val=sma(close,sma1Period)
ema1strength=10000*(ema1val-ema1val[1])/ema1val[1]

ema2val=ema(close,ema2Period)
sma2val=sma(close,sma2Period)
ema2strength=10000*(ema2val-ema2val[1])/ema2val[1]

plot(ema1val,color=blue,linewidth=1)
plot(sma1val,color=orange,linewidth=1)
plot(ema2val,color=navy,linewidth=1)
plot(sma2val,color=red,linewidth=1)

long=crossover(ema1val,sma1val) and (ema1strength > strength1) 
short=crossunder(ema2val,sma2val) and (ema2strength < -strength2)

stopval=ema(close,6)
atr=sma((high-low),15)

inlong=0
buy=0
stop=0
if testPeriod()
    if (inlong[1])
        inlong:=inlong[1]
        buy:=close
        stop:=iff((stopval>(stop[1]+delta*atr)),stopval-delta*atr,stop[1])
    if (long) and (not inlong[1])
        strategy.entry("buy",strategy.long)
        inlong:=close
        buy:=close
        stop:=stopval-delta*atr
plot(buy,color=iff(close<inlong,red,lime),style=columns,transp=90,linewidth=1)
plot(stop,color=iff((short or (stopval<stop)) and (close<inlong),red,lime),style=columns,transp=60,linewidth=1)
if testPeriod()
    if (short or (stopval<stop)) and (inlong[1])
        strategy.close("buy")
        inlong:=0
        stop:=0
        buy:=0



もっと