거래 시스템을 최적화하기 위한 위험 수익률과 결합된 Z-점수 모멘텀 ATR 손절매 전략

ATR RR MA
생성 날짜: 2025-02-20 13:40:12 마지막으로 수정됨: 2025-02-27 17:41:05
복사: 1 클릭수: 398
avatar of ianzeng123 ianzeng123
2
집중하다
319
수행원

거래 시스템을 최적화하기 위한 위험 수익률과 결합된 Z-점수 모멘텀 ATR 손절매 전략 거래 시스템을 최적화하기 위한 위험 수익률과 결합된 Z-점수 모멘텀 ATR 손절매 전략

개요

이 전략은 여러 기술적 지표들을 결합한 완전한 거래 시스템으로, 주로 Z 점수를 기반으로 거래량과 K선 엔터티 크기의 비정상적인 값을 측정하고, ATR을 사용하여 동적 스톱로스를 설정한다. 이 시스템은 또한 수익 목표를 최적화하기 위해 리스크 수익 비율을 통합하고, 다차원적인 기술적 분석을 통해 신뢰할 수 있는 거래 신호를 제공한다.

전략 원칙

전략의 핵심 논리는 다음과 같은 핵심 구성 요소를 기반으로 합니다.

  1. Z 점수 분석: 거래량과 K선 엔티티의 표준 차이를 계산하고, 시장의 비정상적인 활성을 식별
  2. 트렌드 확인: 인접한 K 선의 하위점과 종전 가격을 분석하여 트렌드 방향을 확인합니다.
  3. ATR 중지: 동적 ATR 값을 사용하여 중지 위치를 설정하여 더 유연한 위험 제어를 제공합니다.
  4. 리스크/수익 비율: 설정된 RR 비율을 기반으로 수익 목표를 자동으로 계산합니다.
  5. 시각적 표시: 거래 신호와 중요한 가격 수준을 차트에 표시합니다.

전략적 이점

  1. 다차원 신호 확인: 거래량, 가격 운동 및 트렌드 방향을 결합하여 거래 신호의 신뢰성을 향상시킵니다.
  2. 동적 위험 관리: ATR을 통해 상쇄 손실에 적응하여 시장의 변동에 더 잘 적응할 수 있습니다.
  3. 유연한 변수 구성: Z 스코어 마이너스, ATR 배수 및 리스크 수익률을 조정할 수 있습니다.
  4. 정확한 출입 시점: Z 스코어 특이점을 사용하여 중요한 거래 기회를 식별하십시오.
  5. 명확한 시각화: 차트에 입력 포인트, 중지 손실 및 수익 목표가 명확하게 표시됩니다.

전략적 위험

  1. 변수 민감성: Z 점수 마이너스 및 ATR 배수의 설정은 거래 빈도 및 위험 제어에 직접적인 영향을 미칩니다.
  2. 시장 환경 의존성: 낮은 변동성 환경에서 거래 신호가 덜 발생할 수 있습니다.
  3. 계산 복잡성: 여러 지표 계산으로 신호 생성 지연이 발생할 수 있다.
  4. 슬라이드 포인트 위험: 빠른 시장에서 실제 실행 가격과 신호 가격의 오차가 발생할 수 있습니다.
  5. 가짜 브레이크 위험: 재조합 시장에서 잘못된 브레이크 신호를 유발할 수 있다.

전략 최적화 방향

  1. 시장 환경 필터: 시장 변동률 필터를 추가하여 다른 시장 환경에서 동적으로 변수를 조정합니다.
  2. 신호 확인 메커니즘: RSI 또는 MACD와 같은 크로스 검증을 위해 더 많은 기술 지표를 도입하십시오.
  3. 포지션 관리 최적화: 변동성 및 계정 리스크에 기반한 역동적인 포지션 조정
  4. 다중 시간 주기의 분석: 더 높은 시간 주기를 통합하는 경향을 확인하여 거래 성공률을 높인다.
  5. 신호 필터링 최적화: 가짜 신호를 줄이기 위해 추가 필터링 조건을 추가

요약하다

이 전략은 Z 점수 분석, ATR 중지 및 위험 수익 비율 최적화를 결합하여 완전한 거래 시스템을 구축한다. 시스템의 장점은 다차원적인 신호 확인과 유연한 위험 관리이지만, 여전히 파라미터 설정과 시장 환경의 영향을 고려해야합니다. 제안된 최적화 방향을 통해 전략은 안정성과 적응성을 더욱 향상시킬 수 있다.

전략 소스 코드
/*backtest
start: 2024-10-01 00:00:00
end: 2025-02-18 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/

//@version=5
strategy("admbrk | Candle Color & Price Alarm with ATR Stop", overlay=true, initial_capital=50, default_qty_type=strategy.cash, default_qty_value=200, commission_type=strategy.commission.percent, commission_value=0.05, pyramiding=3)

// **Risk/Reward ratio (RR) as input**
rr = input.float(2.0, title="Risk/Reward Ratio (RR)", step=0.1)

// **Z-score calculation function**
f_zscore(src, len) =>
    mean = ta.sma(src, len)     
    std = ta.stdev(src, len)
    (src - mean) / std

// **Z-score calculations**
len = input(20, "Z-Score MA Length")
z1 = input.float(1.5, "Threshold z1", step=0.1)
z2 = input.float(2.5, "Threshold z2", step=0.1)

z_volume = f_zscore(volume, len)
z_body = f_zscore(math.abs(close - open), len)

i_src = input.string("Volume", title="Source", options=["Volume", "Body size", "Any", "All"])

float z = na
if i_src == "Volume"
    z := z_volume
else if i_src == "Body size"
    z := z_body
else if i_src == "Any"
    z := math.max(z_volume, z_body)
else if i_src == "All"
    z := math.min(z_volume, z_body)

// **Determine trend direction**
green = close >= open
red = close < open

// **Long and Short signals**
longSignal = barstate.isconfirmed and red[1] and low < low[1] and green
shortSignal = barstate.isconfirmed and green[1] and high > high[1] and red

long = longSignal and (z >= z1)
short = shortSignal and (z >= z1)

// **ATR calculation (for ATR Stop)**
atrLength = input.int(14, title="ATR Length")
atrMultiplier = input.float(1.5, title="ATR Stop Multiplier")
atrValue = ta.atr(atrLength)

// **ATR-based stop-loss calculation**
long_atr_stop = close - atrValue * atrMultiplier
short_atr_stop = close + atrValue * atrMultiplier

// **Stop-loss setting (set to the lowest/highest wick of the last two bars)**
long_sl = ta.lowest(low, 2)  // Long stop-loss (lowest of the last 2 bars)
short_sl = ta.highest(high, 2) // Short stop-loss (highest of the last 2 bars)

// **Take-profit calculation (with RR)**
long_tp = close + (close - long_sl) * rr
short_tp = close - (short_sl - close) * rr

triggerAlarm(symbol)=>
    status = close
    var string message = na
    alarmMessageJSON = syminfo.ticker + message +"\\n" + "Price: " + str.tostring(status) 
    
if long
    // Open Long position
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", from_entry="Long", stop=math.max(long_sl, long_atr_stop), limit=long_tp)
    

if short
    // Open Short position
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", from_entry="Short", stop=math.min(short_sl, short_atr_stop), limit=short_tp)
    

// **Coloring the candles (BUY = Green, SELL = Red)**
barcolor(long ? color.green : short ? color.red : na)

// **Add entry/exit markers on the chart**
plotshape(long, title="BUY Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small, text="BUY")
plotshape(short, title="SELL Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small, text="SELL")

// **Plot TP and SL markers on exits**
exitLong = strategy.position_size < strategy.position_size[1] and strategy.position_size[1] > 0
exitShort = strategy.position_size > strategy.position_size[1] and strategy.position_size[1] < 0

plotshape(exitLong, title="Long Exit", location=location.abovebar, color=color.blue, style=shape.labeldown, size=size.tiny, text="TP/SL")
plotshape(exitShort, title="Short Exit", location=location.belowbar, color=color.orange, style=shape.labelup, size=size.tiny, text="TP/SL")

// **Add alerts**
alertcondition(long, title="Long Signal", message="Long signal triggered!")
alertcondition(short, title="Short Signal", message="Short signal triggered!")