マルチレベルATRダイナミック利益取引戦略

ATR SMA TR MF TP SL MA AATR
作成日: 2024-12-05 16:49:57 最終変更日: 2024-12-05 16:49:57
コピー: 2 クリック数: 477
1
フォロー
1617
フォロワー

マルチレベルATRダイナミック利益取引戦略

概要

これは,自己適応平均リアル波幅 (ATR) 計算と動力ベースのトレンド検出を統合した多層の取引戦略である.この戦略の最も顕著な特徴は,ATRベースの4つの退出レベルと3つの固定パーセントレベルを組み合わせた7段階の利益のメカニズムである.この混合的アプローチは,トレーダーに市場の変動に応じて動的に調整し,多空市場で体系的に利益を上げることを可能にします.

戦略原則

戦略の核心には以下の重要な要素があります.

  1. 強化型リアル波幅計算:最も顕著な価格動きを考慮して市場の波動性を測定する.
  2. 動量因子統合:最近の価格変動に基づいてATRを調整し,より適応的にする.
  3. 自動ATR計算:従来のATRを動量因子に合わせて調整し,波動期間により敏感にします.
  4. トレンドの強度測定: 複雑なアルゴリズムでトレンドの強さを評価する.
  5. 7段階の収益メカニズム:ATRベースの4つの退出レベルと3つの固定パーセントレベルを含む.

戦略的優位性

  1. 適応力:ダイナミックなATR計算によって異なる市場条件に適応する.
  2. リスク管理の改善: 多層利回りメカニズムにより,リスクの制御が体系化されています.
  3. 高柔軟性:多空市場でも同様に効率的に動作する.
  4. パラメータの可変性:異なる取引スタイルに対応するために複数の可変性パラメータを提供します.
  5. システム化された実行: 明確な入場・出場ルールにより 感情的な取引が減る

戦略リスク

  1. パラメータの敏感性: パラメータの不適切な設定は,過度取引や機会を逃す可能性があります.
  2. 市場条件依存: 激しい波動や横断市場では不良なパフォーマンスを発揮する可能性がある.
  3. 複合性のリスク: 多層の利益の仕組みは,実行の難しさを増やす可能性があります.
  4. スライドポイントの影響:複数の得益者がスライドポイントに顕著に影響を受ける可能性があります.
  5. 資金管理要求: 多層の収益戦略を実行するために十分な資金が必要です.

戦略最適化の方向性

  1. 動的パラメータ調整:市場の状況に応じてパラメータを自動的に調整する.
  2. 市場環境フィルター:市場環境識別メカニズムを追加
  3. リスク管理の強化: ダイナミック・ストップ・ローズメカニズム導入
  4. 実行最適化: スライドポイントの影響を減らすために,収益化メカニズムを簡素化する.
  5. 返信の枠組みの改善:現実の取引要素の追加

要約する

この戦略は,自己適応ATRと多層リターンメカニズムを組み合わせて,トレーダーに包括的な取引システムを提供します.その優点は,異なる市場条件に適応し,システム化された方法によってリスクを管理できることです.いくつかの潜在的リスクがあるものの,適切な最適化とリスク管理によって,この戦略は効果的な取引ツールになることができます.その革新的な多層リターンメカニズムは,リスクをコントロールしながら利益を最大化しようとするトレーダーに特に適しています.

ストラテジーソースコード
/*backtest
start: 2024-11-04 00:00:00
end: 2024-12-04 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PresentTrading

// The SuperATR 7-Step Profit Strategy is a multi-layered trading strategy that combines adaptive ATR and momentum-based trend detection 
// with a sophisticated 7-step take-profit mechanism. This approach utilizes four ATR-based exit levels and three fixed percentage levels, 
// enabling flexible and dynamic profit-taking in both long and short market positions.

//@version=5
strategy("SuperATR 7-Step Profit - Strategy [presentTrading] ", overlay=true, precision=3, commission_value= 0.1, commission_type=strategy.commission.percent, slippage= 1, currency=currency.USD, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, initial_capital=10000)

// ————————
// User Inputs
// ————————
short_period = input.int(3, minval=1, title="Short Period")
long_period = input.int(7, minval=1, title="Long Period")
momentum_period = input.int(7, minval=1, title="Momentum Period")
atr_sma_period = input.int(7, minval=1, title="ATR SMA Period for Confirmation")
trend_strength_threshold = input.float(1.618, minval=0.0, title="Trend Strength Threshold", step=0.1)

// ————————
// Take Profit Inputs
// ————————
useMultiStepTP = input.bool(true, title="Enable Multi-Step Take Profit")

// ATR-based Take Profit Inputs
atrLengthTP = input.int(14, minval=1, title="ATR Length for Take Profit")
atrMultiplierTP1 = input.float(2.618, minval=0.1, title="ATR Multiplier for TP Level 1")
atrMultiplierTP2 = input.float(5.0, minval=0.1, title="ATR Multiplier for TP Level 2")
atrMultiplierTP3 = input.float(10.0, minval=0.1, title="ATR Multiplier for TP Level 3")
atrMultiplierTP4 = input.float(13.82, minval=0.1, title="ATR Multiplier for TP Level 4")

// Fixed Percentage Take Profit Inputs
tp_level_percent1 = input.float(3.0, minval=0.1, title="Fixed TP Level 1 (%)")
tp_level_percent2 = input.float(8.0, minval=0.1, title="Fixed TP Level 2 (%)")
tp_level_percent3 = input.float(17.0, minval=0.1, title="Fixed TP Level 3 (%)")

// Take Profit Percentages for Each Level
tp_percent_atr = input.float(10.0, minval=0.1, maxval=100, title="Percentage to Exit at Each ATR TP Level")
tp_percent_fixed = input.float(10.0, minval=0.1, maxval=100, title="Percentage to Exit at Each Fixed TP Level")


// —————————————
// Helper Functions
// —————————————

// Function to calculate True Range with enhanced volatility detection
calculate_true_range() =>
    prev_close = close[1]
    tr1 = high - low
    tr2 = math.abs(high - prev_close)
    tr3 = math.abs(low - prev_close)
    true_range = math.max(tr1, tr2, tr3)
    true_range

// ———————————————
// Indicator Calculations
// ———————————————

// Calculate True Range
true_range = calculate_true_range()

// Calculate Momentum Factor
momentum = close - close[momentum_period]
stdev_close = ta.stdev(close, momentum_period)
normalized_momentum = stdev_close != 0 ? (momentum / stdev_close) : 0
momentum_factor = math.abs(normalized_momentum)

// Calculate Short and Long ATRs
short_atr = ta.sma(true_range, short_period)
long_atr = ta.sma(true_range, long_period)

// Calculate Adaptive ATR
adaptive_atr = (short_atr * momentum_factor + long_atr) / (1 + momentum_factor)

// Calculate Trend Strength
price_change = close - close[momentum_period]
atr_multiple = adaptive_atr != 0 ? (price_change / adaptive_atr) : 0
trend_strength = ta.sma(atr_multiple, momentum_period)

// Calculate Moving Averages
short_ma = ta.sma(close, short_period)
long_ma = ta.sma(close, long_period)

// Determine Trend Signal
trend_signal = (short_ma > long_ma and trend_strength > trend_strength_threshold) ? 1 :
               (short_ma < long_ma and trend_strength < -trend_strength_threshold) ? -1 : 0

// Calculate Adaptive ATR SMA for Confirmation
adaptive_atr_sma = ta.sma(adaptive_atr, atr_sma_period)

// Determine if Trend is Confirmed with Price Action
trend_confirmed = (trend_signal == 1 and close > short_ma and adaptive_atr > adaptive_atr_sma) or (trend_signal == -1 and close < short_ma and adaptive_atr > adaptive_atr_sma)

// —————————————
// Trading Logic
// —————————————

// Entry Conditions
long_entry = trend_confirmed and trend_signal == 1
short_entry = trend_confirmed and trend_signal == -1

// Exit Conditions
long_exit = strategy.position_size > 0 and short_entry
short_exit = strategy.position_size < 0 and long_entry



// Execute Long Trades
if long_entry
    strategy.entry("Long Entry", strategy.long)
if long_exit
    strategy.close("Long Entry")

// Execute Short Trades
if short_entry
    strategy.entry("Short Entry", strategy.short)
if short_exit
    strategy.close("Short Entry")

// ————————————————
// Multi-Step Take Profit Logic
// ————————————————

if useMultiStepTP
    // Calculate ATR for Take Profit Levels
    atrValueTP = ta.atr(atrLengthTP)

    // Long Position Take Profit Levels
    if strategy.position_size > 0
        // ATR-based Take Profit Prices
        tp_priceATR1_long = strategy.position_avg_price + atrMultiplierTP1 * atrValueTP
        tp_priceATR2_long = strategy.position_avg_price + atrMultiplierTP2 * atrValueTP
        tp_priceATR3_long = strategy.position_avg_price + atrMultiplierTP3 * atrValueTP
        tp_priceATR4_long = strategy.position_avg_price + atrMultiplierTP4 * atrValueTP

        // Fixed Percentage Take Profit Prices
        tp_pricePercent1_long = strategy.position_avg_price * (1 + tp_level_percent1 / 100)
        tp_pricePercent2_long = strategy.position_avg_price * (1 + tp_level_percent2 / 100)
        tp_pricePercent3_long = strategy.position_avg_price * (1 + tp_level_percent3 / 100)

        // Set ATR-based Take Profit Exits
        strategy.exit("TP ATR 1 Long", from_entry="Long Entry", qty_percent=tp_percent_atr, limit=tp_priceATR1_long)
        strategy.exit("TP ATR 2 Long", from_entry="Long Entry", qty_percent=tp_percent_atr, limit=tp_priceATR2_long)
        strategy.exit("TP ATR 3 Long", from_entry="Long Entry", qty_percent=tp_percent_atr, limit=tp_priceATR3_long)
        strategy.exit("TP ATR 4 Long", from_entry="Long Entry", qty_percent=tp_percent_atr, limit=tp_priceATR4_long)

        // Set Fixed Percentage Take Profit Exits
        strategy.exit("TP Percent 1 Long", from_entry="Long Entry", qty_percent=tp_percent_fixed, limit=tp_pricePercent1_long)
        strategy.exit("TP Percent 2 Long", from_entry="Long Entry", qty_percent=tp_percent_fixed, limit=tp_pricePercent2_long)
        strategy.exit("TP Percent 3 Long", from_entry="Long Entry", qty_percent=tp_percent_fixed, limit=tp_pricePercent3_long)

    // Short Position Take Profit Levels
    if strategy.position_size < 0
        // ATR-based Take Profit Prices
        tp_priceATR1_short = strategy.position_avg_price - atrMultiplierTP1 * atrValueTP
        tp_priceATR2_short = strategy.position_avg_price - atrMultiplierTP2 * atrValueTP
        tp_priceATR3_short = strategy.position_avg_price - atrMultiplierTP3 * atrValueTP
        tp_priceATR4_short = strategy.position_avg_price - atrMultiplierTP4 * atrValueTP

        // Fixed Percentage Take Profit Prices
        tp_pricePercent1_short = strategy.position_avg_price * (1 - tp_level_percent1 / 100)
        tp_pricePercent2_short = strategy.position_avg_price * (1 - tp_level_percent2 / 100)
        tp_pricePercent3_short = strategy.position_avg_price * (1 - tp_level_percent3 / 100)

        // Set ATR-based Take Profit Exits
        strategy.exit("TP ATR 1 Short", from_entry="Short Entry", qty_percent=tp_percent_atr, limit=tp_priceATR1_short)
        strategy.exit("TP ATR 2 Short", from_entry="Short Entry", qty_percent=tp_percent_atr, limit=tp_priceATR2_short)
        strategy.exit("TP ATR 3 Short", from_entry="Short Entry", qty_percent=tp_percent_atr, limit=tp_priceATR3_short)
        strategy.exit("TP ATR 4 Short", from_entry="Short Entry", qty_percent=tp_percent_atr, limit=tp_priceATR4_short)

        // Set Fixed Percentage Take Profit Exits
        strategy.exit("TP Percent 1 Short", from_entry="Short Entry", qty_percent=tp_percent_fixed, limit=tp_pricePercent1_short)
        strategy.exit("TP Percent 2 Short", from_entry="Short Entry", qty_percent=tp_percent_fixed, limit=tp_pricePercent2_short)
        strategy.exit("TP Percent 3 Short", from_entry="Short Entry", qty_percent=tp_percent_fixed, limit=tp_pricePercent3_short)


// ——————————
// Plotting
// ——————————

plot(short_ma, color=color.blue, title="Short MA")
plot(long_ma, color=color.orange, title="Long MA")

// Plot Buy and Sell Signals
//plotshape(long_entry, title="Long Entry", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text="Buy")
//plotshape(short_entry, title="Short Entry", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text="Sell")

// Optional: Plot Trend Strength for analysis
// Uncomment the lines below to display Trend Strength on a separate chart pane
// plot(trend_strength, title="Trend Strength", color=color.gray)
// hline(trend_strength_threshold, title="Trend Strength Threshold", color=color.gray, linestyle=hline.style_dashed)
// hline(-trend_strength_threshold, title="Trend Strength Threshold", color=color.gray, linestyle=hline.style_dashed)