ダイナミックストップロスと目標利益に基づくEMA複数コスト加重平均コスト戦略


作成日: 2024-01-19 15:16:53 最終変更日: 2024-01-19 15:16:53
コピー: 2 クリック数: 778
1
フォロー
1617
フォロワー

ダイナミックストップロスと目標利益に基づくEMA複数コスト加重平均コスト戦略

概要

この戦略は,ダイナミックな多指数移動平均を入場シグナルとして採用し,ストップと目標の利益を追跡するメカニズムと組み合わせてリスクと利益を管理する.この戦略は,トレンドを識別するためにEMAの滑らかな性質を充分に活用し,DCAの複数の投入によってコストを制御する.さらに,ダイナミックなストップと目標の利益の設定を統合して,全戦略をより賢く,自動化します.

戦略原則

指標計算

  • EMA5,EMA10,EMA20,EMA50,EMA100,EMA200指数の移動平均
  • ATR平均真波幅

市内への入場信号

価格が設定されたEMA周期に近づいたり,または通過したときに入札シグナルが生成される.EMA周期はカスタマイズされ,典型的には5,10,20,50,100,200サイクルを選択する.この戦略は,価格がEMA上下1%の範囲で入札条件として採用する.

リスク管理

リスク管理の統合:

  1. ATRストップ:ATRが設定された値を超えると清算ストップ
  2. 市場投入の最大回数規制:過剰投入を避ける
  3. ダイナミック・トラッキング・ストップ:価格によるリアルタイム変動による trailing stop

利益の仕組み

目標利益のレベルを設定し,価格が目標値を超えると退出する

戦略的優位分析

  1. EMAのトレンド認識を活用して,短期的な波動をフィルターする
  2. DCAのコストを分散させ,低価格で高値買いを避ける
  3. 複数のEMAポートフォリオで上場率を向上させる
  4. ダイナミックストップREAL-TIME制御損失
  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)