この戦略は,価格の高点と低点を識別するためにウィリアムズフラクタル指標を使用し,ABCD形状と組み合わせてトレンドの方向を判断し,トレンドが確認された後に入場し,中短線トレンドの利益を追跡します.
ウィリアムズ・フラクタル指数を使用して価格の高低点を識別し,異なる形状によって牛市のABCD形状または熊市のABCD形状であると判断する.
ABCDの形状判断基準:
ABとCDの間の距離は近い,BCとCDの間の距離は一定の比率要求を満たしている ((0.382-0.886と1.13-2.618の間) 。
D点より低いC点は牛市形,D点より高いC点は熊市形。
barssince関数によって,前方の方向のFractalが現在の方向から最近にあることを判断し,現在の全体的な傾向方向を判断する.
ABCDの形状を認識したときに,入場して多/空を入れ,ストップとストップを設定し,ショートラインのトレンドを追跡する.
ウィリアムズ・フラクタル指標の補助判断により,ターニングポイントをより正確に識別することができる.
ABCD形状判断基準はシンプルで信頼性があり,プログラムしやすい.
barssince関数と組み合わせて,大トレンドの方向を判断することで,偽突破による損失を効率的に減らすことができます.
ストップ・ストップ・ストップを設定すると,ショートラインのトレンドを追跡して利益を得ることができます.
Williams Fractalは遅滞しており,ターニングポイントを逃して損失を招く可能性があります.
中間短線に複数の重複するABCD形が存在し,識別エラーを引き起こす可能性がある。
大トレンドの判断が不正確である場合,中短線取引は閉じ込められやすい.
ストップダメージ設定が小さすぎると,攻撃されやすく,大きすぎると,追跡効果が悪くなります.
対応の最適化方法:
ターニングポイントをより効果的に識別する方法を模索するために,他の指標を補助判断として使用することができます.
ABCD形状のパラメータを最適化して判断を厳格に確実にする.
大傾向を判断する方法を最適化して,大傾向を誤って判断するのを防ぎます.
異なるストップ・ストップ比率をテストし,最適のストップ・ストップポイントを見つけます.
MACD,KDJなどの他の指標を活用して,より正確な入学時期を探し出すことができます.
異なる品種の異なる周期に応じてパラメータを最適化して,その品種周期に最も適した止損停止点を見つけることができる.
市場変化に応じて最適化できる全サイクルを取って,最適なパラメータの組み合わせを探します.
均線などの指標のフィルタリングで入場信号を組み合わせて,戦略の安定性を高めることができる.
機械学習アルゴリズムを導入し,より多くのデータ訓練モデルを利用して,識別精度を向上させることができます.
この戦略の全体的な考え方は明確で信頼性があり,ウィリアムズフラクタル指標とABCD形状判断の短線トレンド方向を利用し,トレンドフィルターとストップ・ストップ設定を組み合わせてトレンドを追跡して利益を得る.戦略の最適化スペースは広く,入場シグナル,パラメータ最適化,トレンド判断などの面で改善でき,戦略を異なる市場環境に適したものにすることができる.全体的に言えば,この戦略は, discretionary + quantの組み合わせの戦略モデルとして,強力な実用性を持っています.
/*backtest
start: 2023-09-16 00:00:00
end: 2023-09-23 00:00:00
period: 45m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// @version=4
// @author=Daveatt - BEST
// ABCD Pattern Strat
StrategyName = "BEST ABCD Pattern Strategy"
ShortStrategyName = "BEST ABCD Pattern Strategy"
// strategy(title=StrategyName, shorttitle=ShortStrategyName, overlay=true,
// pyramiding=2, default_qty_value=100, precision=7, currency=currency.USD,
// commission_value=0.2,commission_type=strategy.commission.percent, initial_capital=1000000,
// default_qty_type=strategy.fixed)
filterBW = input(false, title="filter Bill Williams Fractals?")
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////// UTILITIES ///////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// ||-----------------------------------------------------------------------------------------------------||
// ||--- Fractal Recognition Functions: ---------------------------------------------------------------||
isRegularFractal(mode, _high, _low) =>
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, _high, _low) =>
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
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
////////////////////////////// ABCD PATTERN ///////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
f_abcd()=>
_r = timeframe.period
_g = barmerge.gaps_off
_l = barmerge.lookahead_on
_high = high
_low = low
filteredtopf = filterBW ? isRegularFractal(1, _high, _low) : isBWFractal(1, _high, _low)
filteredbotf = filterBW ? isRegularFractal(-1, _high, _low) : isBWFractal(-1, _high, _low)
// ||--- ZigZag:
istop = filteredtopf
isbot = filteredbotf
topcount = barssince(istop)
botcount = barssince(isbot)
zigzag = (istop and topcount[1] > botcount[1] ? _high[2] :
isbot and topcount[1] < botcount[1] ? _low[2] : na)
x = valuewhen(zigzag, zigzag, 4)
a = valuewhen(zigzag, zigzag, 3)
b = valuewhen(zigzag, zigzag, 2)
c = valuewhen(zigzag, zigzag, 1)
d = valuewhen(zigzag, zigzag, 0)
xab = (abs(b-a)/abs(x-a))
xad = (abs(a-d)/abs(x-a))
abc = (abs(b-c)/abs(a-b))
bcd = (abs(c-d)/abs(b-c))
// ABCD Part
_abc = abc >= 0.382 and abc <= 0.886
_bcd = bcd >= 1.13 and bcd <= 2.618
_bull_abcd = _abc and _bcd and d < c
_bear_abcd = _abc and _bcd and d > c
_bull = _bull_abcd and not _bull_abcd[1]
_bear = _bear_abcd and not _bear_abcd[1]
[_bull, _bear, zigzag]
lapos_x = timenow + round(change(time)*12)
[isLong, isShort, zigzag] = f_abcd()
plot(zigzag, title= 'ZigZag', color=color.black, offset=-2)
plotshape(isLong, style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.normal, text="ABCD", textcolor=color.white)
plotshape(isShort, style=shape.labeldown, location=location.abovebar, color=color.new(color.maroon, 0), size=size.normal, text="ABCD", textcolor=color.white)
long_entry_price = valuewhen(isLong, close, 0)
short_entry_price = valuewhen(isShort, close, 0)
sinceNUP = barssince(isLong)
sinceNDN = barssince(isShort)
buy_trend = sinceNDN > sinceNUP
sell_trend = sinceNDN < sinceNUP
//////////////////////////
//* Profit Component *//
//////////////////////////
//////////////////////////// MinTick ///////////////////////////
fx_pips_value = syminfo.type == "forex" ? syminfo.mintick*10 : 1
input_tp_pips = input(100, "Backtest Profit Goal (in USD)",minval=0)*fx_pips_value
input_sl_pips = input(20, "Backtest STOP Goal (in USD)",minval=0)*fx_pips_value
tp = buy_trend? long_entry_price + input_tp_pips : short_entry_price - input_tp_pips
sl = buy_trend? long_entry_price - input_sl_pips : short_entry_price + input_sl_pips
plot_tp = buy_trend and high[1] <= tp ? tp : sell_trend and low[1] <= tp ? tp : na
plot_sl = buy_trend and low[1] >= sl ? sl : sell_trend and high[1] >= sl ? sl : na
plot(plot_tp, title="TP", style=plot.style_circles, linewidth=3, color=color.blue)
plot(plot_sl, title="SL", style=plot.style_circles, linewidth=3, color=color.red)
longClose = isShort
shortClose = isLong
strategy.entry("Long", 1, when=isLong)
// strategy.close("Long", when=longClose )
strategy.exit("XL","Long", limit=tp, when=buy_trend, stop=sl)
strategy.entry("Short", 0, when=isShort)
// strategy.close("Short", when=shortClose )
strategy.exit("XS","Short", when=sell_trend, limit=tp, stop=sl)