複数期間のスーパートレンドトレンド取引戦略の動的組み合わせアルゴリズム

ATR MTF EMA RSI
作成日: 2025-01-06 16:38:12 最終変更日: 2025-01-06 16:38:12
コピー: 2 クリック数: 482
1
フォロー
1617
フォロワー

複数期間のスーパートレンドトレンド取引戦略の動的組み合わせアルゴリズム

概要

この戦略は、マルチタイムフレームのスーパートレンドインジケーターに基づいた適応型トレンド追跡システムです。 15 分、5 分、2 分の 3 つの異なる期間のスーパートレンド信号を統合することにより、包括的なトレンド識別フレームワークを構築します。この戦略では、時間フィルターを使用して、最も活発な取引時間中にのみ実行されるようにし、夜間のリスクを回避するために、一日の終わりにポジションを自動的にクローズします。

戦略原則

この戦略の核心は、複数の期間におけるトレンドの一貫性を通じて取引シグナルを確認することです。具体的には:

  1. スーパートレンド ラインは、ATR 期間と乗数を使用して各期間ごとに計算されます。
  2. 3 つの時間枠すべてで強気シグナルが現れた場合 (価格がスーパートレンド ラインを上回った場合)、買いがトリガーされます。
  3. 価格が 5 分間のスーパートレンド ラインを下回るか、取引日の終了に達すると、売りがトリガーされます。
  4. タイムゾーンと取引セッション フィルター (デフォルト 09:30 ~ 15:30) を設定して取引時間を制御します。

戦略的優位性

  1. 多次元トレンド確認により、信号の信頼性が向上し、誤ったブレイクスルーのリスクが効果的に軽減されます。
  2. 適応型スーパートレンド パラメータ設定により、戦略はさまざまな市場変動環境に適応できます。
  3. 厳格な時間管理メカニズムにより、非効率的な取引期間による干渉を回避します。
  4. わかりやすいビジュアル インターフェースにより、すべての期間のトレンド ステータスが表示されます。
  5. 柔軟なポジション管理システムはパーセンテージ設定をサポートします。

戦略リスク

  1. 横ばいで変動の激しい市場では、取引シグナルが過剰に生成され、取引コストが増加する可能性があります。
  2. フィルタリング条件が複数あると、潜在的に利益を生む機会を逃してしまう可能性があります。
  3. パラメータの最適化に依存し、市場環境によってパラメータの調整が必要になる場合があります。
  4. 計算の複雑さが高く、プログラムの実行効率に問題が生じる可能性があります。

戦略最適化の方向性

  1. 市場の状況に応じてスーパートレンドパラメータを動的に調整するボラティリティ適応メカニズムを導入します。
  2. トレンド判断の精度を向上させるために、ボリューム確認インジケーターを追加します。
  3. 最適な取引時間を自動的に識別するインテリジェントな時間フィルタリング アルゴリズムを開発します。
  4. ポジション管理アルゴリズムを最適化して、より洗練されたリスク管理を実現します。
  5. 市場環境分類モジュールを追加し、さまざまな市場特性に基づいて差別化された戦略を採用します。

要約する

この戦略は、複数期間のトレンド分析と厳格なリスク管理システムを通じて、堅牢な取引システムを構築します。最適化の余地はあるものの、コアロジックは堅牢であり、さらなる開発や実際のアプリケーションに適しています。システムのモジュール設計は、将来の拡張にも適した基盤を提供します。

ストラテジーソースコード
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Multi-Timeframe Supertrend Strategy", 
         overlay=true, 
         shorttitle="MTF Supertrend TF", 
         default_qty_type=strategy.percent_of_equity, 
         default_qty_value=100, 
         initial_capital=50000, 
         currency=currency.USD)

// === Input Parameters === //
atrPeriod = input.int(title="ATR Period", defval=10, minval=1)
factor = input.float(title="Factor", defval=3.0, step=0.1)

// === Time Filter Parameters === //
// Define the trading session using input.session
// Format: "HHMM-HHMM", e.g., "0930-1530"
sessionInput = input("0930-1530", title="Trading Session")

// Specify the timezone (e.g., "Europe/Istanbul")
// Refer to the list of supported timezones: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
timezoneInput = input.string("Europe/Istanbul", title="Timezone", tooltip="Specify a valid IANA timezone (e.g., 'Europe/Istanbul', 'America/New_York').")

// === Calculate Supertrend for Different Timeframes === //
symbol = syminfo.tickerid

// 15-Minute Supertrend
[st_15m, dir_15m] = request.security(symbol, "15", ta.supertrend(factor, atrPeriod), lookahead=barmerge.lookahead_off)

// 5-Minute Supertrend
[st_5m, dir_5m] = request.security(symbol, "5", ta.supertrend(factor, atrPeriod), lookahead=barmerge.lookahead_off)

// 2-Minute Supertrend
[st_2m, dir_2m] = request.security(symbol, "2", ta.supertrend(factor, atrPeriod), lookahead=barmerge.lookahead_off)

// === Current Timeframe Supertrend === //
[st_current, dir_current] = ta.supertrend(factor, atrPeriod)

// === Time Filter: Check if Current Bar is Within the Trading Session === //
in_session = true

// === Define Trend Directions Based on Supertrend === //
is_up_15m = close > st_15m
is_up_5m  = close > st_5m
is_up_2m  = close > st_2m
is_up_current = close > st_current

// === Buy Condition === //
buyCondition = is_up_15m and is_up_5m and is_up_2m and is_up_current and in_session and strategy.position_size == 0

// === Sell Conditions === //
// 1. Price falls below the 5-minute Supertrend during trading session
sellCondition1 = close < st_5m

// 2. End of Trading Day: Sell at the close of the trading session
is_new_day = ta.change(time("D"))
sellCondition2 = not in_session and is_new_day

// Combined Sell Condition: Only if in Position
sellSignal = (sellCondition1 and in_session) or sellCondition2
sellCondition = sellSignal and strategy.position_size > 0

// === Execute Trades === //
if (buyCondition)
    strategy.entry("Buy", strategy.long)

if (sellCondition)
    strategy.close("Buy")

// === Plot Supertrend Lines === //
// Plotting current timeframe Supertrend
plot(st_current, title="Current TF Supertrend", color=is_up_current ? color.green : color.red, linewidth=2, style=plot.style_line)

// Plotting higher timeframe Supertrend lines
plot(st_15m, title="15m Supertrend", color=is_up_15m ? color.green : color.red, linewidth=1, style=plot.style_line)
plot(st_5m, title="5m Supertrend", color=is_up_5m ? color.green : color.red, linewidth=1, style=plot.style_line)
plot(st_2m, title="2m Supertrend", color=is_up_2m ? color.green : color.red, linewidth=1, style=plot.style_line)

// === Plot Buy and Sell Signals === //
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, 
          color=color.green, style=shape.labelup, text="BUY", size=size.small)

plotshape(series=sellCondition, title="Sell Signal", location=location.abovebar, 
          color=color.red, style=shape.labeldown, text="SELL", size=size.small)

// === Optional: Background Color to Indicate Position === //
bgcolor(strategy.position_size > 0 ? color.new(color.green, 90) : na, title="In Position Background")

// === Alerts === //
// Create alerts for Buy and Sell signals
alertcondition(buyCondition, title="Buy Alert", message="Buy signal generated by MTF Supertrend Strategy with Time Filter.")
alertcondition(sellCondition, title="Sell Alert", message="Sell signal generated by MTF Supertrend Strategy with Time Filter.")