EMAのマルチDCA戦略,ストップ損失と利益目標の追尾

作者: リン・ハーンチャオチャン,日付: 2024年1月19日 15:16:53
タグ:

img

概要

この戦略は,リスク管理のためのトライリングストップ損失および利益目標メカニズムと組み合わせて,ダイナミックな複数のEMAをエントリーシグナルとして利用する.マルチDCAエントリを通じてトレンドを特定し,コストを制御するためにEMAのスムーズな性質を利用する.さらに,適応型ストップ損失と利益の取り付け機能の統合は自動化プロセスを強化する.

戦略の論理

インディケーター

  • EMA5, EMA10, EMA20, EMA50, EMA100, EMA200 について
  • 平均実範囲 (ATR)

入力信号

選択した EMA 期間の範囲内で価格が横断または移動するときにロングエントリを誘発する.典型的な EMA には 5, 10, 20, 50, 100, 200 期間の入場基準が含まれる.この戦略は EMA の 1% の範囲を使用する.

リスク管理

複数のリスク管理メカニズムを含んでいる.

  1. ATR Stop Loss: ATR 値を超えるとすべてのポジションを閉じる
  2. 入力頻度制限: 入力の最大数を制御する
  3. 価格変動に基づくダイナミックストップ損失

利益 を 得る

出口の利益目標価格レベルを設定する

利点

  1. 騒音フィルタリングのEMAを使用して傾向を特定する
  2. 複数のDCAエントリによるコスト平均
  3. EMA コンボを用いた強化入国信号
  4. 適応型ストップ損失メカニズム
  5. 利益保護のために利益管理を

リスク と 改善

  1. EMAの調整は,異なる市場のために最適化する必要があります
  2. 過剰なDCA記入が資本を過剰に占める可能性があります
  3. ストップ・ロスの割合はバックテストが必要

強化戦略

  1. 傾向をより良く識別するために先進的なEMAシステムを活用する
  2. DCA 周波数とストップ損失パーセントの多変数最適化
  3. 価格変動予測に機械学習モデルを組み込む
  4. 総資本利用を管理するためのポジションサイズモジュールを統合する

結論

この戦略には,EMAトレンド検出,マルチDCAコスト平均化,ストップ損失追尾,目標利益取得などが含まれています.パラメータ調整とリスク管理の強化には十分な可能性が残っています.全体的に見ると,この高度に適応性があり,汎用的な戦略は投資家に安定したアルファ生成能力を提供しています.


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

//@version=4
strategy("EMA DCA Strategy with Trailing Stop and Profit Target", overlay=true )

// Define the investment amount for when the condition is met
investment_per_condition = 6

// Define the EMAs
ema5 = ema(close, 5)
ema10 = ema(close, 10)
ema20 = ema(close, 20)
ema50 = ema(close, 50)
ema100 = ema(close, 100)
ema200 = ema(close, 200)

// Define ATR sell threshold
atr_sell_threshold = input(title="ATR Sell Threshold", type=input.integer, defval=10, minval=1)

// Helper function to find if the price is within 1% of the EMA
isWithin1Percent(price, ema) =>
    ema_min = ema * 0.99
    ema_max = ema * 1.01
    price >= ema_min and price <= ema_max

// Control the number of buys
var int buy_count = 0
buy_limit = input(title="Buy Limit", type=input.integer, defval=3000)

// Calculate trailing stop and profit target levels
trail_percent = input(title="Trailing Stop Percentage", type=input.integer, defval=1, minval=0, maxval=10)
profit_target_percent = input(title="Profit Target Percentage", type=input.integer, defval=3, minval=1, maxval=10)

// Determine if the conditions are met and execute the strategy
checkConditionAndBuy(emaValue, emaName) =>
    var int local_buy_count = 0 // Create a local mutable variable
    if isWithin1Percent(close, emaValue) and local_buy_count < buy_limit
        strategy.entry("Buy at " + emaName, strategy.long, qty=investment_per_condition / close, alert_message ="Buy condition met for " + emaName)
        local_buy_count := local_buy_count + 1
        // alert("Buy Condition", "Buy condition met for ", freq_once_per_bar_close)
        
    local_buy_count // Return the updated local_buy_count

// Add ATR sell condition
atr_condition = atr(20) > atr_sell_threshold
if atr_condition
    strategy.close_all()
    buy_count := 0 // Reset the global buy_count when selling

// Strategy execution
buy_count := checkConditionAndBuy(ema5, "EMA5")
buy_count := checkConditionAndBuy(ema10, "EMA10")
buy_count := checkConditionAndBuy(ema20, "EMA20")
buy_count := checkConditionAndBuy(ema50, "EMA50")
buy_count := checkConditionAndBuy(ema100, "EMA100")
buy_count := checkConditionAndBuy(ema200, "EMA200")

// Calculate trailing stop level
trail_offset = close * trail_percent / 100
trail_level = close - trail_offset

// Set profit target level
profit_target_level = close * (1 + profit_target_percent / 100)

// Exit strategy: Trailing Stop and Profit Target
strategy.exit("TrailingStop", from_entry="Buy at EMA", trail_offset=trail_offset, trail_price=trail_level)
strategy.exit("ProfitTarget", from_entry="Buy at EMA",  when=close >= profit_target_level)

// Plot EMAs
plot(ema5, title="EMA 5", color=color.red)
plot(ema10, title="EMA 10", color=color.orange)
plot(ema20, title="EMA 20", color=color.yellow)
plot(ema50, title="EMA 50", color=color.green)
plot(ema100, title="EMA 100", color=color.blue)
plot(ema200, title="EMA 200", color=color.purple)


もっと