반전 단기 브레이크아웃 거래 전략

저자:차오장, 날짜: 2023-11-21 17:03:32
태그:

img

전반적인 설명

이 전략은 단기적 역전 거래 기회를 포착하는 것을 목표로 한다. N 연속 상향 바와 M 연속 하향 바 이후 짧은 포지션을 열고 닫을 것이다. 또한 시간 프레임 필터와 스톱 로스/프로프트 기능을 통합한다.

논리

  1. 입력 매개 변수: 연속 상향 막대수 N, 연속 하향 막대수 M
  2. 정의:
    • ups는 up-bar의 수, 가격> 가격 [1] 다음 +1, 그렇지 않으면 0으로 다시 설정
    • dns는 다운 바의 수, 가격<가격[1] 다음 +1, 그렇지 않으면 0으로 다시 설정
  3. 입구: 위 ≥N에서 짧은 위치, dns ≥M에서 가까운 위치
  4. 출구: 고정 스톱 로스/이익 취득 또는 기간 종료

장점

  1. 단기 거래에 적합한 역전 거래 기회를 포착합니다.
  2. 다양한 거래 계획에 대한 유연한 시간 프레임 설정
  3. 리스크 관리를 용이하게 하는 스톱 로스/프로프트 취득이 탑재된 경우

위험성

  1. 단기 회환은 실패하고 다시 회환이 손실로 이어질 수 있습니다.
  2. 합리적인 N, M 매개 변수 필요, 너무 크거나 너무 작다 불리한
  3. 부적절한 정지 시간은 시간 손실을 중지 할 수 없습니다

최적화 방향

  1. 트렌드 트레이드를 피하기 위해 트렌드 인디케이터와 결합
  2. 파라미터의 동적 조정 N, M
  3. 스톱 로스 메커니즘을 최적화

결론

전략은 통계적 K-라인 패턴을 통해 단기 거래 기회를 포착합니다. 합리적인 매개 변수 조정 및 위험 통제 조치는 안정적인 수익에 중요합니다. 추세 분석과 동적 매개 변수 조정의 결합에 대한 추가 개선은 더 나은 성과로 이어질 수 있습니다.


/*backtest
start: 2023-11-13 00:00:00
end: 2023-11-20 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

// Strategy
strategy("Up/Down Short Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)

// There will be no short entries, only exits from long.
strategy.risk.allow_entry_in(strategy.direction.short)

consecutiveBarsUp = input(1, title='Consecutive Bars Up')
consecutiveBarsDown = input(1, title='Consecutive Bars Down')

price = close

ups = 0.0
ups := price > price[1] ? nz(ups[1]) + 1 : 0

dns = 0.0
dns := price < price[1] ? nz(dns[1]) + 1 : 0

// Strategy Backtesting
startDate  = input(timestamp("2021-01-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("2021-12-31T00:00:00"), type = input.time, title='Backtesting End Date')

time_cond  = true

//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = (time(timeframe.period, startendtime))
timetoclose = na(time(timeframe.period, startendtime))

// Stop Loss & Take Profit Tick Based
enablesltp = input(false, title='Enable Take Profit & Stop Loss')
stopTick = input(5.0, title='Stop Loss Ticks', type=input.float) / 100
takeTick = input(10.0, title='Take Profit Ticks', type=input.float) / 100

longStop = strategy.position_avg_price - stopTick
shortStop = strategy.position_avg_price + stopTick
shortTake = strategy.position_avg_price - takeTick
longTake = strategy.position_avg_price + takeTick

plot(strategy.position_size > 0 and enablesltp ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesltp ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enablesltp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enablesltp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")

// Alert messages
message_enterlong  = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")
message_takeprofit = input("", title="Take Profit message")
message_stoploss = input("", title="Stop Loss message")

// Strategy Execution
if (ups >= consecutiveBarsUp) and time_cond and timetobuy
    strategy.entry("Long", strategy.long, stop = high + syminfo.mintick, alert_message = message_enterlong)
    
if (dns >= consecutiveBarsDown) and time_cond and timetobuy
    strategy.entry("Short", strategy.short, stop = low + syminfo.mintick, alert_message = message_entershort)
    
if strategy.position_size > 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closeshort)
    
if strategy.position_size > 0 and enablesltp and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_takeprofit)
if strategy.position_size < 0 and enablesltp and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_stoploss)






더 많은