양적 거래 전략을 위한 ZZ 지표와 결합된 윌리엄스 프랙탈

저자:차오장, 날짜: 2024-01-29 15:24:30
태그:

img

전반적인 설명

이것은 빌 윌리엄스 프랙탈 이론과 ZZ 지표의 사용을 결합한 양적 거래 전략입니다. 윌리엄스 프랙탈의 계산을 통해 시장 트렌드를 판단하고 트렌드를 따르는 거래를 구현하기 위해 ZZ 지표를 사용하여 지원 / 저항 라인을 그리면서 잠재적 인 브레이크아웃 포인트를 식별합니다.

전략 원칙

전략은 먼저 윌리엄스 프랙탈을 계산하여 현재 프랙탈이 상승하거나 감소하는지 결정합니다. 상승하는 프랙탈이라면 현재 추세가 상승하고 있다고 생각합니다. 떨어지는 프랙탈이라면 현재 추세가 하락하고 있다고 생각합니다.

그 다음 ZZ 지표의 지지 및 저항 라인을 프랙탈 포인트에 기초하여 그린다. 가격이 상승 프랙탈에 대응하는 저항 라인을 뚫고 갈 경우, 긴 거리로 갈 수 있다. 가격이 떨어지는 프랙탈에 대응하는 지지 라인을 뚫고 갈 경우, 짧은 거리로 갈 수 있다.

이러한 조합을 통해 트렌드의 변화를 적시에 파악하고 트렌드를 따르는 거래를 구현할 수 있습니다.

이점 분석

이 전략은 두 가지 다른 기술적 분석 방법 - 윌리엄스 프랙탈과 ZZ 지표 - 을 결합하여 더 많은 거래 기회를 발견합니다.

시장 트렌드의 전환점을 적시에 판단할 수 있으며 주요 트렌드 방향을 파악하기 위해 좋은 스톱 로스/프로프트 취업 기준을 가지고 있습니다. 또한 ZZ 지표는 불필요한 손실을 피하기 위해 일부 잘못된 브레이크오프를 필터링 할 수 있습니다.

일반적으로 이 전략은 위험과 수익을 균형 잡기 위해 트렌드 판단과 특정 입점 선택을 모두 고려합니다.

위험 분석

이 전략의 가장 큰 위험은 프랙탈 판단과 ZZ 지표가 잘못된 거래 신호를 발산하여 불필요한 손실로 이어질 수 있다는 것입니다. 예를 들어, 저항선을 뚫고 나면 가격이 빠르게 다시 떨어질 수 있으며 상승 추세를 유지할 수 없습니다.

또한, 프랙탈을 계산하는 방식은 시간 프레임을 잘못 설정하면 잘못된 판단으로 이어질 수 있습니다. 시간 프레임을 너무 짧게 설정하면 잘못된 파열의 확률이 증가합니다.

이러한 위험을 줄이기 위해 프랙탈의 계산 매개 변수를 적절히 조정하고 잘못된 신호를 줄이기 위해 필터링 조건을 증가하십시오. 또한 단일 거래 손실 크기를 제어하기 위해 더 넓은 스톱 로스를 설정하십시오.

최적화 방향

이 전략은 다음과 같은 측면에서 더 이상 최적화 될 수 있습니다.

  1. MACD 또는 볼린거 밴드 같은 모멘텀 지표 필터를 추가하여 일부 잘못된 브레이크를 피합니다.

  2. 프랙탈 매개 변수 설정을 최적화하고 최고와 최저의 계산을 조정하고 더 정확한 트렌드 판단을 얻기 위해 시간 프레임을 단축합니다.

  3. 트렌드 정확성을 판단하고 인간의 한계를 피하기 위해 기계 학습 알고리즘을 증가시킵니다.

  4. 시장 변동성에 기초한 적응식 스톱 로스 메커니즘을 추가합니다.

  5. 딥러닝 알고리즘을 사용하여 전체 매개 변수 설정을 최적화합니다.

요약

이 전략은 윌리엄스 프랙탈 이론과 ZZ 지표를 능숙하게 결합함으로써 시장 트렌드 변화에 대한 신속한 탐지 및 포착을 달성합니다. 높은 승률을 유지하고 장기적인 초과 수익을 얻을 것으로 예상됩니다. 더 많은 필터와 AI 기능을 도입함으로써 다음 단계는 전략 안정성과 수익률을 더욱 향상시킬 것으로 예상됩니다.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy(title = "robotrading ZZ-8 fractals", shorttitle = "ZZ-8", overlay = true, default_qty_type = strategy.percent_of_equity, initial_capital = 100, default_qty_value = 100, commission_value = 0.1)

//Settings
needlong  = input(true, defval = true, title = "Long")
needshort = input(false, defval = true, title = "Short")
filterBW = input(false, title="filter Bill Williams Fractals")
showll = input(true, title = "Show levels")
showff = input(true, title = "Show fractals (repaint!)")
showdd = input(true, title = "Show dots (repaint!)")
showbg = input(false, title = "Show background")
showlb = input(false, title = "Show drawdown")
startTime = input(defval = timestamp("01 Jan 2000 00:00 +0000"), title = "Start Time", type = input.time, inline = "time1")
finalTime = input(defval = timestamp("31 Dec 2099 23:59 +0000"), title = "Final Time", type = input.time, inline = "time1")

//Variables
loss = 0.0
maxloss = 0.0
equity = 0.0
truetime = true

//Fractals
isRegularFractal(mode) =>
    ret = mode == 1 ? high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] : mode == -1 ? low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] : false
isBWFractal(mode) =>
    ret = mode == 1 ? high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1] and high[2] > high[0] : mode == -1 ? low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0] : false
filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)

//Triangles
plotshape(filteredtopf and showff, title='Filtered Top Fractals', style=shape.triangledown, location=location.abovebar, color= color.red, offset=-2)
plotshape(filteredbotf and showff, title='Filtered Bottom Fractals', style=shape.triangleup, location=location.belowbar, color= color.lime, offset=-2)

//Levels
hh = 0.0
ll = 0.0
hh := filteredtopf ? high[2] : hh[1]
ll := filteredbotf ? low[2] : ll[1]

//Trend
trend = 0
trend := high >= hh[1] ? 1 : low <= ll[1] ? -1 : trend[1]

//Lines
hcol = showll and hh == hh[1] and close < hh ? color.lime : na
lcol = showll and ll == ll[1] and close > ll ? color.red : na
plot(hh, color = hcol)
plot(ll, color = lcol)

//Dots
// var line hline = na
// if hh != hh[1] and showdd
//     hline := line.new(bar_index - 0, hh[0], bar_index - 2, hh[0], xloc = xloc.bar_index, extend = extend.none, style = line.style_dotted, color = color.lime, width = 1)
// var line lline = na
// if ll != ll[1] and showdd
//     lline := line.new(bar_index - 0, ll[0] - syminfo.mintick, bar_index - 2, ll[0] - syminfo.mintick, xloc = xloc.bar_index, extend = extend.none, style = line.style_dotted, color = color.red, width = 1)
    
//Background
bgcol = showbg == false ? na : trend == 1 ? color.lime : trend == -1 ? color.red : na
bgcolor(bgcol, transp = 80)

//Orders
if hh > 0 and needlong
    strategy.entry("Long", strategy.long, na, stop = hh, when = needlong and truetime)
    strategy.exit("Exit Long", "Long", stop = ll, when = needshort == false)
if ll > 0 and startTime
    strategy.entry("Short", strategy.short, na, stop = ll, when = needshort and truetime)
    strategy.exit("Exit Short", "Short", stop = hh, when = needlong == false)
if time > finalTime
    strategy.close_all()
    strategy.cancel("Long")
    strategy.cancel("Short")

if showlb

    //Drawdown
    max = 0.0
    max := max(strategy.equity, nz(max[1]))
    dd = (strategy.equity / max - 1) * 100
    min = 100.0
    min := min(dd, nz(min[1]))
    
    //Max loss size
    equity := strategy.position_size != strategy.position_size[1] ? strategy.equity : equity[1]
    loss := equity < equity[1] ? ((equity / equity[1]) - 1) * 100 : 0
    maxloss := min(nz(maxloss[1]), loss)
    
    //Label
    min := round(min * 100) / 100
    maxloss := round(maxloss * 100) / 100
    labeltext = "Drawdown: " + tostring(min) + "%" + "\nMax.loss " + tostring(maxloss) + "%"
    var label la = na
    label.delete(la)
    tc = min > -100 ? color.white : color.red
    osx = timenow + round(change(time)*50)
    osy = highest(100)
    la := label.new(x = osx, y = osy, text = labeltext, xloc = xloc.bar_time, yloc = yloc.price, color = color.black, style = label.style_labelup, textcolor = tc)

더 많은