스퀴즈 백테스트 트랜스포머 v2.0


생성 날짜: 2024-04-28 14:09:26 마지막으로 수정됨: 2024-04-28 14:09:26
복사: 0 클릭수: 536
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

스퀴즈 백테스트 트랜스포머 v2.0

개요

엑스트레이트 리테크 변형 금강 v2.0은 엑스트레이트 방식의 전략을 기반으로 한 양적 거래 시스템이다. 그것은 진출, 손실 및 정지 비율, 최대 포지션 보유 시간 등의 파라미터를 설정하여 특정 시간 범위에서 전략에 대한 리테크를 수행한다. 이 전략은 다방향 거래를 지원하며 거래 방향을 더 많이 또는 공백으로 조정할 수 있다. 동시에, 이 전략은 풍부한 리테크 기간 설정 옵션을 제공하여 고정 시간 또는 최대 리테크 시간을 편리하게 선택할 수 있다.

전략 원칙

  1. 먼저, 사용자 설정된 재검사 기간 매개 변수에 따라 재검사의 시작 시간 및 종료 시간을 결정한다.
  2. 재검토 기간 동안, 현재 포지션이 없는 경우와 가격이 진입 가격에 닿는 경우 ((포지션 개시 비율에 따라 계산), 포지션을 개시하고 동시에 스톱로스 및 스톱 스톱 가격을 설정합니다 ((스톱로스 및 스톱 스톱 비율에 따라 계산).
  3. 만약 이미 지분을 보유하고 있다면, 이전의 스톱스트로스 명령을 취소하고 새로운 스톱스트로스 가격을 재설정한다 (현재 지분을 보유한 평균 가격에 따라 계산).
  4. 최대 보유 시간 (Maximum Holding Time) 이 설정되어 있다면, 보유 시간이 최대 값에 도달했을 때, 강제적으로 평지한다.
  5. 이 전략은 양방향의 거래, 즉 상장과 공백을 지원합니다.

전략적 이점

  1. 매개 변수 설정은 다양한 시장 상황과 거래 요구에 따라 조정할 수 있는 유연하다.
  2. 다방향 거래를 지원하여 다양한 시장에서 수익을 얻을 수 있습니다.
  3. 풍부한 재검토 기간 설정 옵션을 제공하여 역사 데이터 재검토 및 분석을 편리하게 수행할 수 있습니다.
  4. 손해 중지 및 중지 설정은 위험을 효과적으로 제어하고 자금 사용 효율성을 향상시킵니다.
  5. 최대 보유 시간 설정은 너무 오래 보유하여 시장 위험에 노출되는 것을 방지합니다.

전략적 위험

  1. 입시 가격, 중단 가격, 그리고 중단 가격의 설정은 전략 수익에 큰 영향을 미치며, 부적절한 매개 변수 설정은 손실을 초래할 수 있다.
  2. 시장의 급격한 변동이 있을 때, 포지션 개시 후 즉시 스톱로스를 유발하는 상황이 발생할 수 있으며, 이로 인해 손실이 발생할 수 있다.
  3. 만약 지분을 보유할 때 최대 지분 시간 평점을 촉발한다면, 이후의 수익 기회를 놓칠 수 있다.
  4. 이 전략은 특정 상황 (동기시장과 같은) 에서 좋지 않을 수 있습니다.

전략 최적화 방향

  1. 더 많은 기술 지표 또는 시장 정서 지표를 도입하는 것이 고려 될 수 있습니다. 입시, 중단 및 중단 조건을 최적화하여 전략의 안정성과 수익성을 향상시킬 수 있습니다.
  2. 최대 포지션 시간 설정은 시장의 변동성과 포지션 손실 상황에 따라 동적으로 조정할 수 있으며, 고정 시간 평점 포지션으로 인해 발생할 수있는 기회 비용을 피할 수 있습니다.
  3. 흔들리는 시장의 특성에 대해, 흔들리는 구역의 돌파구 또는 트렌드 반전 확인과 같은 논리를 추가하여, 빈번한 거래로 인한 비용을 줄일 수 있다.
  4. 포지션 관리 및 자금 관리 전략에 참여하여 단 거래 위험 허브를 제어하고 자금 활용 효율성과 안정성을 향상시키는 것을 고려하십시오.

요약하다

엑스트레이트 리테크 변형 금강 v2.0은 엑스트레이트 방식의 전략을 기반으로 한 양적 거래 시스템으로, 유연한 파라미터 설정과 다방향 거래 지원을 통해 다양한 시장 환경에서 거래 할 수 있습니다. 동시에, 풍부한 리테크 기간 설정 옵션과 스톱 스톱 손실 설정은 사용자가 역사적 데이터 분석과 위험 관리에 도움이 될 수 있습니다. 그러나, 전략의 성능은 파라미터 설정에 영향을 많이 받으며, 전략의 안정성과 수익성을 높이기 위해 전략의 안정성과 수익성을 높이기 위해 시장 특성과 거래 요구에 따라 최적화 및 개선이 필요합니다. 향후에는 더 많은 기술 지표, 최대 포지션 보유 시간 조정, 변동 시장 전략을 최적화하고 포지션 및 자본 관리를 강화하는 등의 측면에서 최적화를 고려할 수 있습니다.

전략 소스 코드
/*backtest
start: 2023-04-22 00:00:00
end: 2024-04-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5

strategy(title="Squeeze Backtest by Shaqi v2.0", overlay=true, pyramiding=0, currency="USD", process_orders_on_close=true, commission_type=strategy.commission.percent, commission_value=0.075, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, backtest_fill_limits_assumption=0)
R0 = "6 Hours"
R1 = "12 Hours"
R2 = "24 Hours"
R3 = "48 Hours"
R4 = "1 Week"
R5 = "2 Weeks"
R6 = "1 Month"
R7 = "Maximum"

BL = "low"
BH = "high"
BO = "open"
BC = "close"
BHL= "mid (hl)"
BOC = "mid (oc)"

LONG = "LONG"
SHORT = "SHORT"

direction = input.string(title="Direction", defval=LONG, options=[LONG, SHORT], group="Squeeze Settings")
strategy.risk.allow_entry_in(direction == LONG ? strategy.direction.long : strategy.direction.short)
openPercent = input.float(1.4, "Open, %", minval=0.01, maxval=100, step=0.1, inline="Percents", group="Squeeze Settings") * 0.01
closePercent = input.float(0.6, "Close, %", minval=0.01, maxval=100, step=0.1, inline="Percents", group="Squeeze Settings") * 0.01
stopPercent = input.float(0.8, "Stop Loss, %", minval=0.01, maxval=100, step=0.1, inline="Percents", group="Squeeze Settings") * 0.01
isMaxBars = input.bool(true, "Max Bars To Sell", inline="MaxBars", group="Squeeze Settings")
maxBars = input.int(10, title="", minval=0, maxval=1000, step=1, inline="MaxBars", group="Squeeze Settings")
bind = input.string(BC, "Bind", options=[BL, BH, BO, BC, BHL, BOC], group="Squeeze Settings")
isRange = input.bool(true, "Fixed Range", inline="Range", group="Backtesting Period")
rangeStart = input.string(R2, "", options=[R0, R1, R2, R3, R4, R5, R6, R7], inline="Range", group="Backtesting Period")
periodStart = input(timestamp("12 Apr 2024 00:00 +0000"), "Backtesting Start", group="Backtesting Period")
periodEnd = input(timestamp("20 Apr 2024 00:00 +0000"), "Backtesting End", group="Backtesting Period")

int startDate = na
int endDate = na
if isRange
    if rangeStart == R0
        startDate := timenow - 21600000
        endDate := timenow
    else if rangeStart == R1
        startDate := timenow - 43200000
        endDate := timenow
    else if rangeStart == R2
        startDate := timenow - 86400000
        endDate := timenow
    else if rangeStart == R3
        startDate := timenow - 172800000
        endDate := timenow
    else if rangeStart == R4
        startDate := timenow - 604800000
        endDate := timenow
    else if rangeStart == R5
        startDate := timenow - 1209600000
        endDate := timenow
    else if rangeStart == R6
        startDate := timenow - 2592000000
        endDate := timenow
    else if rangeStart == R7
        startDate := time
        endDate := timenow
else 
    startDate := periodStart
    endDate := periodEnd
    
float bindOption = na
if bind == BL
    bindOption := low
else if bind == BH
    bindOption := high
else if bind == BO
    bindOption := open
else if bind == BC
    bindOption := close
else if bind == BHL
    bindOption := hl2
else
    bindOption := ohlc4

afterStartDate = (time >= startDate)
beforeEndDate = (time <= endDate)
periodCondition = true
notInTrade = strategy.position_size == 0
inTrade = strategy.position_size != 0

barsFromEntry = ta.barssince(strategy.position_size[0] > strategy.position_size[1])
entry = strategy.position_size[0] > strategy.position_size[1]
entryBar = barsFromEntry == 0
notEntryBar = barsFromEntry != 0
openLimitPrice = direction == LONG ? (bindOption - bindOption * openPercent) : (bindOption + bindOption * openPercent)

closeLimitPriceEntry = openLimitPrice * (direction == LONG ? 1 + closePercent : 1 - closePercent)
closeLimitPrice = strategy.position_avg_price * (direction == LONG ? 1 + closePercent : 1 - closePercent)

stopLimitPriceEntry = direction == LONG ? openLimitPrice - openLimitPrice * stopPercent : openLimitPrice + openLimitPrice * stopPercent
stopLimitPrice = direction == LONG ? strategy.position_avg_price - strategy.position_avg_price * stopPercent : strategy.position_avg_price + strategy.position_avg_price * stopPercent

if periodCondition and notInTrade
    strategy.entry(direction == LONG ? "BUY" : "SELL", direction == LONG ? strategy.long : strategy.short, limit = openLimitPrice, stop = stopLimitPriceEntry)
    strategy.exit("INSTANT", limit = closeLimitPriceEntry, stop = stopLimitPriceEntry, comment_profit = direction == LONG ? 'INSTANT SELL' : 'INSTANT BUY', comment_loss = 'INSTANT STOP')
if inTrade 
    strategy.cancel("INSTANT")
    strategy.exit(direction == LONG ? "SELL" : "BUY", limit = closeLimitPrice, stop = stopLimitPrice, comment_profit = direction == LONG ? "SELL" : "BUY", comment_loss = "STOP")
if isMaxBars and barsFromEntry == maxBars
    strategy.close_all(comment = "TIMEOUT STOP", immediately = true)



showStop = stopPercent <= 0.20

// plot(showStop ? stopLimitPrice : na, title="Stop Loss Limit Order", force_overlay=true, style=plot.style_linebr, color=#c50202, linewidth=1, offset=1)
// plot(closeLimitPrice, title="Take Profit Limit Order", force_overlay=true, style=plot.style_linebr, color = direction == LONG ? color.red : color.blue, linewidth=1, offset=1)
// plot(strategy.position_avg_price, title="Buy Order Filled Price", force_overlay=true, style=plot.style_linebr, color=direction == LONG ? color.blue : color.red, linewidth=1, offset=1)
plot(showStop ? stopLimitPrice : na, title="Stop Loss Limit Order", force_overlay=true, style=plot.style_linebr, color=#c50202, linewidth=1, offset=0)
plot(closeLimitPrice, title="Take Profit Limit Order", force_overlay=true, style=plot.style_linebr, color = direction == LONG ? color.red : color.blue, linewidth=1, offset=0)
plot(strategy.position_avg_price, title="Buy Order Filled Price", force_overlay=true, style=plot.style_linebr, color=direction == LONG ? color.blue : color.red, linewidth=1, offset=0)

plot(openLimitPrice, title="Trailing Open Position Limit Order", style=plot.style_stepline, color=color.new(direction == LONG ? color.blue : color.red, 30), offset=1)
plot(closeLimitPriceEntry, title="Trailing Close Position Limit Order", style=plot.style_stepline, color=color.new(direction == LONG ? color.red : color.blue, 80), offset=1)
plot(stopLimitPriceEntry, title="Trailing Stop Position Limit Order", style=plot.style_stepline, color=color.new(#c50202, 80), offset=1)