동적 추적 손절매 1/3 K-라인 양적 거래 전략

TRINITY ATR
생성 날짜: 2025-02-18 13:57:33 마지막으로 수정됨: 2025-02-18 13:57:33
복사: 0 클릭수: 345
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

동적 추적 손절매 <sup>1</sup>⁄<sub>3</sub> K-라인 양적 거래 전략

개요

이것은 빌 윌리엄스의 13 K 라인 분석 방법과 동적 추적 중지 기능을 결합한 양적 거래 전략이다. 이 전략은 현재와 이전 K 라인의 구조적 특성을 분석하여 명확한 다공간 신호를 생성하고, 설정 가능한 추적 중지 메커니즘을 사용하여 포지션을 보호하여 정확한 입출장 및 위험 관리를 구현한다.

전략 원칙

이 전략의 핵심 논리는 다음과 같은 몇 가지 핵심 요소에 기반합니다.

  1. K선 3등분 계산: K선 각의 범위를 (최고 가격-최저 가격) 3등분하여 상위 영역과 하위 영역의 경계값을 얻는다.
  2. K선 형태 분류: K선 형태는 오픈 가격과 클로즈 가격의 3등 하위권에 있는 위치에 따라 여러 종류로 분류한다. 예를 들어, 오픈 가격이 하위권에 있고 클로즈 가격이 상위권에 있을 때, 강력한 상향형으로 간주된다.
  3. 신호 생성 규칙: 현재 K선과 이전 K선의 형태를 조합 분석하여 유효한 거래 신호를 결정한다. 예를 들어, 연속적으로 두 개의 K선 모두 강렬한 특성을 나타내면 여러 신호를 유발한다.
  4. 동적 추적 스톱: 지정된 시간 주기 동안 전 N 루트 K 선의 최저 가격 (다중) 또는 최고 가격 (공백) 을 이동 스톱 포인트로 사용한다.

전략적 이점

  1. 논리 명확성: 전략은 직관적인 K선 구조 분석 방법을 사용하고 거래 규칙은 명확하고 이해하기 쉽습니다.
  2. 리스크 관리: 동적으로 추적되는 스톱 로즈 메커니즘을 통해 충분한 수익 공간을 유지하면서 철회 위험을 효과적으로 제어 할 수 있습니다.
  3. 적응력: 전략은 다양한 시장 환경에 따라 조정할 수 있으며, 좋은 적응력을 가지고 있다.
  4. 자동화 수준: 신호 생성에서 포지션 관리에 이르기까지 완전히 자동화되어 인간의 개입이 줄어들었습니다.

전략적 위험

  1. 변동성 시장 위험: 변동성 시장의 경우, 과도한 거래로 이어지는 빈번한 가짜 브레이크 신호가 발생할 수 있습니다.
  2. 폭파 위험: 큰 폭파가 발생했을 때, 추적 중지 손실이 적시에 유발되지 않을 수 있으며, 예상 이상의 손실이 발생할 수 있습니다.
  3. 변수 민감성: 손실을 추적하는 변수 선택은 전략 성능에 큰 영향을 미치며, 부적절한 변수 설정은 조기 출전 또는 보호 부족으로 이어질 수 있다.

전략 최적화 방향

  1. 시장 환경 필터를 추가: 트렌드 지표 또는 변동률 지표를 도입하여 다양한 시장 환경에서 전략 매개 변수를 동적으로 조정할 수 있습니다.
  2. 최적화된 스톱 메커니즘: ATR 지표와 결합하여 더 유연한 스톱 거리를 설정하여 스톱의 적응성을 향상시킬 수 있습니다.
  3. 포지션 관리를 도입: 신호 강도 및 시장의 변동성에 따라 포지션 크기를 조정할 수 있으며, 보다 세밀한 위험 통제를 구현한다.
  4. 출전 최적화: 출전 시기를 최적화하기 위해 수익 목표 또는 기술 지표 보조 판단을 추가할 수 있다.

요약하다

이 전략은 체계적이고 논리적으로 명확한 양자 거래 전략으로, 고전적인 기술적 분석 방법과 현대적인 위험 관리 기술을 결합하여 실용성이 좋습니다. 전략의 설계는 신호 생성, 포지션 관리 및 위험 제어와 같은 실물 거래의 요구 사항을 충분히 고려합니다. 이 전략은 더 나은 최적화 및 개선으로 실제 거래에서 더 나은 성능을 얻을 수 있습니다.

전략 소스 코드
/*backtest
start: 2024-02-18 00:00:00
end: 2025-02-16 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("TrinityBar with Trailing Stop", overlay=true, initial_capital=100000, 
     default_qty_type=strategy.percent_of_equity, default_qty_value=250)

//─────────────────────────────────────────────────────────────
// 1. BAR THIRDS CALCULATIONS
//─────────────────────────────────────────────────────────────
cur_range      = high - low
cur_lowerThird = low + cur_range / 3
cur_upperThird = high - cur_range / 3

prev_range      = high[1] - low[1]
prev_lowerThird = low[1] + prev_range / 3
prev_upperThird = high[1] - prev_range / 3

//─────────────────────────────────────────────────────────────
// 2. DEFINE BULLISH & BEARISH BAR TYPES (CURRENT & PREVIOUS)
//─────────────────────────────────────────────────────────────
// Current bar types
is_1_3 = (open <= cur_lowerThird) and (close >= cur_upperThird)
is_3_3 = (open >= cur_upperThird) and (close >= cur_upperThird)
is_2_3 = (open > cur_lowerThird) and (open < cur_upperThird) and (close >= cur_upperThird)

is_3_1 = (open >= cur_upperThird) and (close <= cur_lowerThird)
is_1_1 = (open <= cur_lowerThird) and (close <= cur_lowerThird)
is_2_1 = (open > cur_lowerThird) and (open < cur_upperThird) and (close <= cur_lowerThird)

// Previous bar types
prev_is_1_3 = (open[1] <= prev_lowerThird) and (close[1] >= prev_upperThird)
prev_is_3_3 = (open[1] >= prev_upperThird) and (close[1] >= prev_upperThird)
prev_is_2_3 = (open[1] > prev_lowerThird) and (open[1] < prev_upperThird) and (close[1] >= prev_upperThird)

prev_is_3_1 = (open[1] >= prev_upperThird) and (close[1] <= prev_lowerThird)
prev_is_1_1 = (open[1] <= prev_lowerThird) and (close[1] <= prev_lowerThird)
prev_is_2_1 = (open[1] > prev_lowerThird) and (open[1] < prev_upperThird) and (close[1] <= prev_lowerThird)

//─────────────────────────────────────────────────────────────
// 3. VALID SIGNAL CONDITIONS
//─────────────────────────────────────────────────────────────
validBuy  = (prev_is_2_3 or prev_is_3_3 or prev_is_1_3) and (is_1_3 or is_3_3)
validSell = (prev_is_2_1 or prev_is_1_1 or prev_is_3_1) and (is_1_1 or is_3_1)

//─────────────────────────────────────────────────────────────
// 4. PLOT SIGNAL TRIANGLES
//─────────────────────────────────────────────────────────────
plotshape(validBuy, title="Valid Buy", style=shape.triangleup, location=location.belowbar, 
     color=color.green, size=size.small, text="B")
plotshape(validSell, title="Valid Sell", style=shape.triangledown, location=location.abovebar, 
     color=color.red, size=size.small, text="S")

//─────────────────────────────────────────────────────────────
// 5. MARKET ORDER EXECUTION BASED ON SIGNALS
//─────────────────────────────────────────────────────────────
if validBuy
    // Close any short positions.
    strategy.close("Short", comment="")
    // If not already long, enter a market long.
    if strategy.position_size <= 0
        strategy.entry("Long", strategy.long, comment="")
        
if validSell
    // Close any long positions.
    strategy.close("Long", comment="")
    // If not already short, enter a market short.
    if strategy.position_size >= 0
        strategy.entry("Short", strategy.short, comment="")

//─────────────────────────────────────────────────────────────
// 6. TRAILING STOP LOSS FUNCTION
//─────────────────────────────────────────────────────────────
// Inputs for trailing stop settings:
trailBars = input.int(title="Trailing Stop Bars Back", defval=1, minval=1)
trailTF   = input.timeframe(title="Trailing Stop Timeframe", defval="")  // "" = current timeframe

// For long positions, use the low from 'trailBars' bars back on the specified timeframe.
// For short positions, use the high from 'trailBars' bars back.
trailStopLong  = request.security(syminfo.tickerid, trailTF, low[trailBars])
trailStopShort = request.security(syminfo.tickerid, trailTF, high[trailBars])

// Apply trailing stops if a position is open.
if strategy.position_size > 0
    strategy.exit("Trailing Stop Long", from_entry="Long", stop=trailStopLong)
if strategy.position_size < 0
    strategy.exit("Trailing Stop Short", from_entry="Short", stop=trailStopShort)