指数関数移動平均をトレイルストップ損失と百分比ストップ損失と組み合わせる株式量取引戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-03 16:25:54
タグ:

img

概要

この戦略の核心は,指数的な移動平均のクロスオーバーをトレーリング・ストップ・ロースとパーセントストップ・ロースを組み合わせて取引信号として利用し,利益とリスクを制御する.この戦略は実行が簡単で,定量的な取引のための株式やその他の金融製品に適用できます.

戦略の論理

  1. 速いEMAと遅いEMAを計算します. 速いEMAは20日,遅いEMAは50日です. 速いEMAが遅いEMAを超えると購入信号を生成し,速いEMAが遅いEMAを下回ると販売信号を生成します.

  2. 入力後,保持方向に基づいてトライリングストップロスを設定します.例えば,ロングポジションでは7%,ショートポジションでは7%.トライリングストップロスは,可能な最大利益をロックするために各バーを調整します.

  3. 同時に,エントリー価格とホールディング方向に基づいてストップ・ロスの価格を設定します.例えば,ロング・トレードではエントリー価格を下回り,2%,ショート・トレードではエントリー価格を下回り2%です.過剰な損失を防ぐためにストップ・ロスの価格は変更されません.

  4. この取引の最終ストップ損失として市場価格に近いストップ損失価格を使用し,ストップ損失オーダーを送信します.

利点

  1. シンプルで実行しやすい 移動平均取引信号です

  2. フォローするストップ・ロスは 可能な限り利益を固定し 誤った信号による不必要な損失を回避します

  3. ストップ損失の割合は直感的で,取引毎の最大損失を制御するために簡単に調整できます.

  4. トレーリングストップと固定ストップを組み合わせることで 利潤が確保され リスクもコントロールできます

リスク と 対策

  1. 音量などのフィルターを追加します 音量や音量などのフィルターを追加します

  2. トレーリングストップは 時には早すぎます トレーリングの割合を少し緩めてください

  3. 不適切な固定ストップ損失設定は,あまりにも攻撃的または保守的であり,テストし,パーセントパラメータを調整する必要があります.

  4. 機械的なストップロスの出口は 市場の逆転の機会を逃す可能性があります ストップトリガーを判断するための技術指標を組み込みます

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

  1. 適正なバランスを見つけるために EMAの異なる組み合わせを試してみてください

  2. 偽信号をフィルタリングするために音量などの指標を追加します

  3. 適切なストップロスの割合を見つけるためにより多くの株をテストします

  4. 市場条件に合わせて 調整できる 適応式ストップを試してください

  5. ストップ・ロスのタイミングを決めるには RSI のような指標を組み込む

概要

この戦略は,移動平均取引信号,トレーリングストップおよび百分比ストップを統合しています.パラメータ最適化を通じて,さまざまな株式および商品の厳格なリスク管理で安定した利益を達成できます.


/*backtest
start: 2023-12-26 00:00:00
end: 2024-01-02 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © wouterpruym1828

//@version=5
strategy(title=" Combining Trailing Stop and Stop loss (% of instrument price)",
     overlay=true, pyramiding=1, shorttitle="TSL&SL%")

//INDICATOR SECTION

// Indicator Input options+
i_FastEMA = input.int(title = "Fast EMA period", minval = 0, defval = 20)
i_SlowEMA = input.int(title = "Slow EMA period", minval = 0, defval = 50)
     
// Calculate moving averages
fastEMA = ta.ema(close, i_FastEMA)
slowEMA = ta.ema(close, i_SlowEMA)

// Plot moving averages
plot(fastEMA, title="Fast SMA", color=color.blue)
plot(slowEMA, title="Slow SMA", color=color.orange)




//STRATEGY SECTION  

// Calculate trading conditions
buy  = ta.crossover(fastEMA, slowEMA)
sell = ta.crossunder(fastEMA, slowEMA)

// STEP 1:
// Configure trail stop loss level with input options (optional)

longTrailPerc = input.float(title="Long Trailing Stop (%)", minval=0.0, step=0.1, defval=7) * 0.01

shortTrailPerc = input.float(title="Short Trailing Stop (%)", minval=0.0, step=0.1, defval=7) * 0.01

//Configure stop loss level with input options (optional)

longStopPerc = input.float(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=2)*0.01

shortStopPerc = input.float(title="Short Stop Loss (%)", minval=0.0, step=0.1, defval=2)*0.01


// STEP 2:
// Determine trail stop loss prices
longTrailPrice = 0.0, shortTrailPrice = 0.0

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

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

// Determine stop loss prices
entryPrice = 0.0

entryPrice := strategy.opentrades.entry_price(strategy.opentrades - 1)


longLossPrice = entryPrice * (1 - longStopPerc)

shortLossPrice = entryPrice * (1 + shortStopPerc)


// Plot stop loss values for confirmation

plot(series=(strategy.position_size > 0) ? longTrailPrice : na,
     color=color.fuchsia, style=plot.style_cross,
     linewidth=2, title="Long Trail Stop")
plot(series=(strategy.position_size < 0) ? shortTrailPrice : na,
     color=color.fuchsia, style=plot.style_cross,
     linewidth=2, title="Short Trail Stop")

plot(series=(strategy.position_size > 0) ? longLossPrice : na,
     color=color.olive, style=plot.style_cross,
     linewidth=2, title="Long Stop Loss")
plot(series=(strategy.position_size < 0) ? shortLossPrice : na,
     color=color.olive, style=plot.style_cross,
     linewidth=2, title="Short Stop Loss")

// Submit entry orders
if (buy)
    strategy.entry("Buy", strategy.long)

if (sell)
    strategy.entry("Sell", strategy.short)


//Evaluating trailing stop or stop loss to use

longStopPrice = longTrailPrice < longLossPrice ? longLossPrice : longTrailPrice

shortStopPrice = shortTrailPrice > shortLossPrice ? shortLossPrice : shortTrailPrice

// STEP 3:
// Submit exit orders for stop price

if (strategy.position_size > 0)
    strategy.exit(id="Buy Stop", stop=longStopPrice)

if (strategy.position_size < 0)
    strategy.exit(id="Sell Stop", stop=shortStopPrice)


もっと