고급 동적 트레일링 스톱로스 및 목표 이익 전략

RSI ATR SMA
생성 날짜: 2024-12-11 14:57:09 마지막으로 수정됨: 2024-12-11 14:57:09
복사: 0 클릭수: 383
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

고급 동적 트레일링 스톱로스 및 목표 이익 전략

개요

이 전략은 역동적으로 트래킹한 스톱로스, 리스크 보상 비율, 그리고 RSI 극한이 빠져나가는 것을 결합한 고급 거래 시스템이다. 전략은 시장의 특정 형태를 식별하여 거래한다. ATR와 최근 하락점을 사용하여 역동적인 스톱로스 지점을 설정하고, 미리 설정된 리스크 수익 비율에 따라 수익 목표를 결정한다. 시스템은 또한 RSI 지표에 기반한 시장 과열/ 과냉 판단 메커니즘을 통합하여 시장이 극한에 도달했을 때 평정 입지를 취할 수 있다.

전략 원칙

전략의 핵심 논리는 다음과 같은 핵심 부분으로 구성됩니다.

  1. 입력 신호는 두 가지 형태를 기반으로 한다: 평행 K선 형태 (대일선이 대일선을 따라간다) 와 쌍용 기침형 K선 형태 (双针形 K線形式).
  2. 동적 추적 스톱은 ATR 곱셈을 사용하여 가장 가까운 N 근 K 선의 최저 가격에 조정하여 스톱이 시장의 변동에 동적으로 적응할 수 있도록합니다.
  3. 이윤 목표는 고정된 리스크/이익 비율 설정에 기초하여, 각 거래의 리스크 값을 계산하여 결정된다.
  4. 포지션 규모는 고정된 위험 금액과 거래 당 위험 가치의 동적으로 계산된다.
  5. RSI 극한 탈퇴 메커니즘은 시장이 너무 뜨거워지거나 너무 추워지면 평지 신호를 유발합니다.

전략적 이점

  1. 동적 위험 관리: ATR과 최근 하위점을 결합하여, 시장의 변동에 따라 스톱 스탠드가 조정될 수 있다.
  2. 정확한 포지션 제어: 고정된 위험 금액에 기반한 포지션 계산 방법은 각 거래의 위험을 일관되게 보장한다.
  3. 다차원적 탈퇴 메커니즘: 추적된 스톱로스, 고정된 수익 목표, RSI 극한과 결합된 삼중 탈퇴 메커니즘.
  4. 유연한 거래방향 선택: 오너, 오피 또는 양방향 거래
  5. 명확한 리스크-리드 설정: 사전 설정된 리스크-리드보다 거래당 수익 목표를 명확하게 설정한다.

전략적 위험

  1. 형태 인식의 정확성 위험: 평행 K선과 바늘형 K선의 식별에는 오류가 있을 수 있다.
  2. Stop loss 설정의 슬라이드 리스크: 급격한 변동이 있는 시장에서 큰 슬라이드 위험에 직면할 수 있다.
  3. RSI 극한이 너무 일찍 빠져나갈 수 있다: 강한 추세 시장에서 더 많은 수익을 놓칠 수 있다.
  4. 고정 리스크 수익률의 한계: 다른 시장 환경에서 최적의 리스크 수익률이 다를 수 있다.
  5. 매개 변수 최적화 과다 적합성 위험: 여러 매개 변수들의 조합은 과도한 최적화를 초래할 수 있다.

전략 최적화 방향

  1. 입력 신호 최적화: 거래량, 트렌드 지표 등과 같은 형상 확인 지표를 추가할 수 있다.
  2. 동적 리스크 수익률: 시장의 변동성에 따라 동적으로 조정된 리스크 수익률.
  3. 지능형 변수 적응: 기계 학습 알고리즘을 도입하여 변수를 동적으로 최적화한다.
  4. 다중 시간 주기의 확인: 더 많은 시간 주기의 신호 확인 메커니즘.
  5. 시장 환경 분류: 다른 시장 환경에 따라 다른 파라미터 조합을 사용합니다.

요약하다

이것은 잘 설계된 거래 전략이며, 여러 정교한 기술적 분석 개념을 결합하여 완전한 거래 시스템을 구축한다. 전략의 장점은 포괄적인 위험 관리 시스템과 유연한 거래 규칙에 있다. 그러나 또한 파라미터 최적화 및 시장 적응성의 문제에 주의를 기울여야 한다.

전략 소스 코드
/*backtest
start: 2024-11-10 00:00:00
end: 2024-12-09 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ZenAndTheArtOfTrading | www.TheArtOfTrading.com
// @version=5
strategy("Trailing stop 1", overlay=true)

// Get user input 
int     BAR_LOOKBACK    = input.int(10, "Bar Lookback")
int     ATR_LENGTH      = input.int(14, "ATR Length")
float   ATR_MULTIPLIER  = input.float(1.0, "ATR Multiplier")
rr                      = input.float(title="Risk:Reward", defval=3)

// Basic definition
var float shares=na
risk = 1000
var float R=na
E = strategy.position_avg_price

// Input option to choose long, short, or both
side = input.string("Long", title="Side", options=["Long", "Short", "Both"])

// RSI exit option
RSIexit = input.string("Yes", title="Exit at RSI extreme?", options=["Yes", "No"])
RSIup = input(75)
RSIdown = input(25)

// Get indicator values 
float atrValue = ta.atr(ATR_LENGTH)

// Calculate stop loss values
var float trailingStopLoss = na 
float longStop  = ta.lowest(low, BAR_LOOKBACK) - (atrValue * ATR_MULTIPLIER)
float shortStop = ta.highest(high, BAR_LOOKBACK) + (atrValue * ATR_MULTIPLIER)

// Check if we can take trades 
bool canTakeTrades = not na(atrValue)
bgcolor(canTakeTrades ? na : color.red)

//Long pattern
    //Two pin bar
onepinbar = (math.min(close,open)-low)/(high-low)>0.6 and math.min(close,open)-low>ta.sma(high-low,14)
twopinbar = onepinbar and onepinbar[1]
notatbottom = low>ta.lowest(low[1],10)
    // Parallel
bigred = (open-close)/(high-low)>0.8 and high-low>ta.sma(high-low,14)
biggreen = (close-open)/(high-low)>0.8 and high-low>ta.sma(high-low,14)
parallel = bigred[1] and biggreen  
atbottom = low==ta.lowest(low,10)

// Enter long trades (replace this entry condition)
longCondition = parallel 
if (longCondition and canTakeTrades and  strategy.position_size == 0 and (side == "Long" or side == "Both"))
    R:= close-longStop
    shares:= risk/R
    strategy.entry("Long", strategy.long,qty=shares)

// Enter short trades (replace this entry condition)
shortCondition = parallel
if (shortCondition and canTakeTrades and strategy.position_size == 0 and (side == "Short" or side == "Both"))
    R:= shortStop - close
    shares:= risk/R
    strategy.entry("Short", strategy.short,qty=shares)

// Update trailing stop
if (strategy.position_size > 0)
    if (na(trailingStopLoss) or longStop > trailingStopLoss)
        trailingStopLoss := longStop
else if (strategy.position_size < 0)
    if (na(trailingStopLoss) or shortStop < trailingStopLoss)
        trailingStopLoss := shortStop
else
    trailingStopLoss := na

// Exit trades with trailing stop
strategy.exit("Long Exit",  "Long",  stop=trailingStopLoss, limit = E + rr*R )
strategy.exit("Short Exit", "Short", stop=trailingStopLoss, limit = E - rr*R)

//Close trades at RSI extreme
if ta.rsi(high,14)>RSIup and RSIexit == "Yes"
    strategy.close("Long")
if ta.rsi(low,14)<RSIdown and RSIexit == "Yes"
    strategy.close("Short")

// Draw stop loss 
plot(trailingStopLoss, "Stop Loss", color.red, 1, plot.style_linebr)