定量的な取引戦略のためのZZ指標と組み合わせたウィリアムズフラクタル

作者: リン・ハーンチャオチャン開催日:2024年1月29日 (日) 15:24:30
タグ:

img

概要

これは,ビル・ウィリアムズフラクタル理論とZZ指標の組み合わせによる定量的な取引戦略である.これは,ウィリアムズフラクタルを計算することによって市場動向を判断し,ZZ指標を使用してトレンドフォロー取引を実施するためにサポート/レジスタンスラインを描き,潜在的なブレイクアウトポイントを特定する.

戦略原則

この戦略は,まずウィリアムズフラクタルを計算し,現在のフラクタルが上昇しているか低下しているか判断する.上昇するフラクタルである場合,現在の傾向が向上していると考えられる.低下するフラクタルである場合,現在の傾向が低下していると考えられる.

ZZインジケーターのサポートとレジスタンスラインは,フラクタルポイントに基づいて描かれる.価格が上昇フラクタルに対応するレジスタンスラインを突破した場合,ロングに行く.価格が落ちるフラクタルに対応するサポートラインを突破した場合,ショートに行く.

このような組み合わせによって,トレンドの変化を迅速に把握し,トレンドをフォローする取引を実施することが可能になります.

利点分析

この戦略は,2つの異なる技術分析方法 - ウィリアムズフラクタルと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)

もっと