고급 양적 거래 전략: 일중 모멘텀과 위험 관리를 기반으로 한 자동 실행 시스템

DOJI SL TP ATR momentum
생성 날짜: 2025-02-21 14:25:50 마지막으로 수정됨: 2025-02-27 16:57:06
복사: 2 클릭수: 446
avatar of ianzeng123 ianzeng123
2
집중하다
319
수행원

고급 양적 거래 전략: 일중 모멘텀과 위험 관리를 기반으로 한 자동 실행 시스템 고급 양적 거래 전략: 일중 모멘텀과 위험 관리를 기반으로 한 자동 실행 시스템

개요

이것은 일일 동력에 기반한 완전히 자동화된 거래 전략이며, 엄격한 위험 관리와 정밀한 포지션 관리 시스템을 결합한다. 이 전략은 주로 런던 거래 시간에 실행되며, 시장 동력의 변화를 식별하고 도지 형태를 배제함으로써 거래 기회를 찾으며, 위험을 제어하기 위해 매일 마감 규칙을 적용한다. 이 전략은 다이내믹 포지션 관리 방법을 사용하며, 계좌 권익에 따라 거래 규모를 자동으로 조정하여, 자금 사용의 최적화를 보장한다.

전략 원칙

전략의 핵심 논리는 여러 핵심 구성 요소에 기반한다. 첫째, 충분한 시장 유동성을 보장하기 위해 거래 시간은 런던 시간대에 제한된다. 진입 신호는 가격 운동에 기반한 돌파구이며, 구체적으로 현재 도선의 고점은 이전 한 줄의 고점을 돌파하거나, 낮은 것은 이전 한 줄의 낮은 점을 돌파하는 것을 요구하며, 방향성 일관성을 충족해야 한다. 가짜 돌파구를 피하기 위해, 전략은 Doji 도선을 명시적으로 배제한다. 전략은 또한 매일 중지하는 규칙을 시행하고, 목표 수익이 달성되면 그날 새로운 포지션을 열지 않는다.

전략적 이점

  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")