高度な定量取引戦略: 日中の勢いとリスク管理に基づく自動実行システム

DOJI SL TP ATR momentum
作成日: 2025-02-21 14:25:50 最終変更日: 2025-02-27 16:57:06
コピー: 2 クリック数: 446
2
フォロー
319
フォロワー

高度な定量取引戦略: 日中の勢いとリスク管理に基づく自動実行システム 高度な定量取引戦略: 日中の勢いとリスク管理に基づく自動実行システム

概要

この戦略は,厳格なリスク管理と正確なポジション管理システムと組み合わせた,日中の動量に基づいた完全に自動化された取引戦略である.この戦略は,主にロンドン取引時間に動作し,市場動力の変化を認識し,ドージー形状を除外して取引機会を探し,リスクを制御するために毎日の止まりルールを適用する.この戦略は,ダイナミックなポジション管理方法を採用し,口座権益に応じて取引規模を自動的に調整し,資金の使用を最適化することを保証する.

戦略原則

戦略の核心的な論理は,いくつかの重要な構成要素の上に構築されている. まず,十分な市場流動性を確保するために,取引時間はロンドン時間帯に制限されている. 入場シグナルは,価格動力の突破に基づいており,具体的には,現在の線の高さが前行の高さを突破することを要求する (多行) または,低さが前行の低さを突破することを要求する (空き),一方,方向性の一致性の要求を満たす必要があります.

戦略的優位性

  1. 総合的なリスク管理: 固定ストップ・ストップ,毎日のストップルール,ダイナミックなポジション管理を含む
  2. 柔軟性:取引の規模は,口座の利害関係に応じて自動的に調整され,異なる資金規模に対応します.
  3. 流動性保障:低流動性のリスクを回避するために,ロンドン取引時間での取引を厳格に制限する
  4. 偽信号フィルタリング:ドージー形状と連続信号を排除することで,偽突破による損失を減らす
  5. 実行論理の明晰さ: 入場・出場条件が明確で,監視・最適化が容易

戦略リスク

  1. 市場変動のリスク: 高い波動期に固定ストップは柔軟性がない
  2. 価格の滑落リスク:市場が急激に波動するときに大きな滑落に直面する可能性がある
  3. トレンド依存性:戦略は,波動的な市場において,より多くの偽信号を生成する可能性がある
  4. パラメータ感度:ストップ・ストップの設定は,戦略のパフォーマンスに大きな影響を与える 解決策は,ダイナミック・ストップ・メカニズムを採用し,市場の変動率フィルターを追加し,トレンド確認指標を導入するなどである.

戦略最適化の方向性

  1. 適応性ストップメカニズムを導入:ATRまたは波動率に基づいてストップ範囲を動的に調整する
  2. 市場環境のフィルターを増やす:トレンドの強さの指標を追加し,トレンドが明確である場合にポジションの保持時間を増加させる
  3. 信号確認メカニズムの最適化:交差量と他の技術指標を組み合わせて信号の信頼性を向上させる
  4. 資金管理の改善:複合リスク管理システム導入,規制の撤回を検討
  5. 市場微細構造分析の強化: 整合された注文フローデータにより入場精度向上

要約する

この戦略は,動量突破,厳格なリスク管理,自動化された実行システムを組み合わせて,完全な取引の枠組みを構築しています.この戦略の主要な優点は,その総合的なリスク管理システムと自己適応性設計にありますが,市場環境の識別と信号フィルタリングの面で最適化が必要である.継続的な改善とパラメータの最適化により,この戦略は,異なる市場環境で安定したパフォーマンスを維持する見込みがあります.

ストラテジーソースコード
/*backtest
start: 2025-01-21 00:00:00
end: 2025-02-08 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/

//@version=6
strategy("Trading Strategy for XAUUSD (Gold) – Automated Execution Plan", overlay=true, initial_capital=10000, currency=currency.USD)

//────────────────────────────
// 1. RISK MANAGEMENT & POSITION SIZING
//────────────────────────────
// Configurable inputs for Stop Loss and Take Profit
sl = input.float(title="Stop Loss ($)", defval=5, step=0.1)
tp = input.float(title="Take Profit ($)", defval=15, step=0.1)

// Volume: 0.01 lots per $100 of equity → lotSize = equity / 10000
lotSize = strategy.equity / strategy.initial_capital

//────────────────────────────
// 2. TRADING HOURS (London Time)
//────────────────────────────
// Get the current bar's timestamp in London time.
londonTime   = time(timeframe.period, "", "Europe/London")
londonHour   = hour(londonTime)
tradingAllowed = (londonHour != 0) and (londonHour < 19)

//────────────────────────────
// 3. DOJI CANDLE DEFINITION
//────────────────────────────
// A candle is considered a doji if the sum of its upper and lower shadows is greater than its body.
upperShadow = high - math.max(open, close)
lowerShadow = math.min(open, close) - low
bodySize    = math.abs(close - open)
isDoji      = (upperShadow + lowerShadow) > bodySize

//────────────────────────────
// 4. ENTRY CONDITIONS
//────────────────────────────
// Buy Signal:
//   • Current candle’s high > previous candle’s high.
//   • Current candle’s low is not below previous candle’s low.
//   • Bullish candle (close > open) and not a doji.
//   • Skip if previous candle already qualified.
buyRaw    = (high > high[1]) and (low >= low[1]) and (close > open) and (not isDoji)
buySignal = buyRaw and not (buyRaw[1] ? true : false)

// Sell Signal:
//   • Current candle’s low < previous candle’s low.
//   • Current candle’s high is not above previous candle’s high.
//   • Bearish candle (close < open) and not a doji.
//   • Skip if previous candle already qualified.
sellRaw    = (low < low[1]) and (high <= high[1]) and (close < open) and (not isDoji)
sellSignal = sellRaw and not (sellRaw[1] ? true : false)

//────────────────────────────
// 5. DAILY TAKE PROFIT (TP) RULE
//────────────────────────────
// Create a day-string (year-month-day) using London time.
// This flag will block new trades for the rest of the day if a TP is hit.
var string lastDay = ""
currentDay = str.tostring(year(londonTime)) + "-" + str.tostring(month(londonTime)) + "-" + str.tostring(dayofmonth(londonTime))
var bool dailyTPHit = false
if lastDay != currentDay
    dailyTPHit := false
    lastDay := currentDay

//────────────────────────────
// 6. TRACK TRADE ENTRY & EXIT FOR TP DETECTION
//────────────────────────────
// We record the TP target when a new trade is entered.
// Then, when a trade closes, if the bar’s high (for long) or low (for short) reached the TP target,
// we assume the TP was hit and block new trades for the day.
var float currentTP = na
var int currentTradeType = 0   // 1 for long, -1 for short

// Detect a new trade entry (transition from no position to a position).
tradeEntered = (strategy.position_size != 0 and strategy.position_size[1] == 0)
if tradeEntered
    if strategy.position_size > 0
        currentTP := strategy.position_avg_price + tp
        currentTradeType := 1
    else if strategy.position_size < 0
        currentTP := strategy.position_avg_price - tp
        currentTradeType := -1

// Detect trade closure (transition from position to flat).
tradeClosed = (strategy.position_size == 0 and strategy.position_size[1] != 0)
if tradeClosed and not na(currentTP)
    // For a long trade, if the bar's high reached the TP target;
    // for a short trade, if the bar's low reached the TP target,
    // mark the daily TP flag.
    if (currentTradeType == 1 and high >= currentTP) or (currentTradeType == -1 and low <= currentTP)
        dailyTPHit := true
    currentTP := na
    currentTradeType := 0

//────────────────────────────
// 7. ORDER EXECUTION
//────────────────────────────
// Only open a new position if no position is open, trading is allowed, and daily TP rule is not active.
if (strategy.position_size == 0) and tradingAllowed and (not dailyTPHit)
    if buySignal
        strategy.entry("Long", strategy.long, qty=lotSize)
    if sellSignal
        strategy.entry("Short", strategy.short, qty=lotSize)

//────────────────────────────
// 8. EXIT ORDERS (Risk Management)
//────────────────────────────
// For long positions: SL = entry price - Stop Loss, TP = entry price + Take Profit.
// For short positions: SL = entry price + Stop Loss, TP = entry price - Take Profit.
if strategy.position_size > 0
    longSL = strategy.position_avg_price - sl
    longTP = strategy.position_avg_price + tp
    strategy.exit("Exit Long", from_entry="Long", stop=longSL, limit=longTP)
if strategy.position_size < 0
    shortSL = strategy.position_avg_price + sl
    shortTP = strategy.position_avg_price - tp
    strategy.exit("Exit Short", from_entry="Short", stop=shortSL, limit=shortTP)

//────────────────────────────
// 9. VISUALIZATION
//────────────────────────────
plotshape(buySignal and tradingAllowed and (not dailyTPHit) and (strategy.position_size == 0), title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(sellSignal and tradingAllowed and (not dailyTPHit) and (strategy.position_size == 0), title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")