역 K라인 돌파 단기 트레이딩 전략


생성 날짜: 2023-11-21 17:03:32 마지막으로 수정됨: 2023-11-21 17:03:32
복사: 0 클릭수: 555
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

역 K라인 돌파 단기 트레이딩 전략

개요

이 전략은 짧은 라인 반전 거래 기회를 잡기 위해 사용된다. 이 전략은 연속 N 루트 K 라인 모두 상승한 후 포지션을 공백하고, 연속 M 루트 K 라인 모두 하락한 후 평점 포지션을 한다. 또한, 이 전략은 시간 제한 및 손실 중지 기능을 추가했다.

원칙

  1. 입력 변수: 연속적으로 상승하는 K선수 N, 연속적으로 감소하는 K선수 M
  2. 논리 정의:
    • ups 통계 수 K선 수, price>price[1]은 +1, 그렇지 않으면 0으로 리셋됩니다.
    • dns 통계 하락 K선 수, price
  3. 입시: ups≥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)