모멘텀 ABCD 패턴 전략

저자:차오장날짜: 2023-09-24 13:08:28
태그:

전반적인 설명

이 전략은 윌리엄스 프랙탈 지표를 사용하여 가격 정점과 바닥을 식별하고 트렌드 방향을 결정하기 위해 ABCD 패턴을 결합합니다. 수익을 위해 중장기 트렌드를 따라가기 위해 트렌드를 확인 한 후 입장을합니다.

전략 논리

  1. 윌리엄스 프랙탈 지표를 사용하여 가격 정점과 바닥을 식별합니다. 상승 또는 하락 ABCD 패턴을 결정하는 데 다른 패턴이 사용됩니다.

  2. ABCD 패턴 식별 기준:

    • AB와 CD 사이의 거리는 비슷하며, BC와 CD 사이의 거리는 특정 비율 요구 사항을 충족합니다 (0.382-0.886와 1.13-2.618 사이).

    • C점보다 낮은 D점은 상승 패턴이고 C점보다 높은 D점은 하락 패턴입니다.

  3. 전체 트렌드 방향을 판단하기 위해 어떤 방향의 프랙탈이 현재에 더 가깝는지 결정하기 위해 바스센스 함수를 사용하십시오.

  4. ABCD 패턴을 확인한 후에 장/단으로 입력하고 중장기 트렌드를 따라 스톱 로스를 설정하고 수익을 취합니다.

이점 분석

  1. 윌리엄스 프랙탈 지표는 전환점을 더 정확하게 식별하는 데 도움이 됩니다.

  2. ABCD 패턴 기준은 간단하고 신뢰할 수 있고 자동화하기 쉽습니다.

  3. 주요 트렌드 방향에 대한 판단은 거짓 파업으로 인한 손실을 피합니다.

  4. 스톱 로스로 트렌드를 따라 진입 후 수익을 취합니다.

위험 분석

  1. 윌리엄스 프랙탈은 뒤쳐지고 전환점을 놓치고 손실을 초래할 수 있습니다.

  2. 여러 개의 ABCD 패턴이 중장기 차트에서 잘못된 식별을 일으킬 수 있습니다.

  3. 잘못된 주요 트렌드 방향은 중장기 거래에 갇힐 위험을 증가시킵니다.

  4. 너무 긴 스톱 손실은 쉽게 멈출 수 있습니다. 너무 넓은 스톱 손실은 잘못된 추적을 일으킬 수 있습니다.

가능한 해결책:

  1. 다른 지표를 테스트하여 전환점을 더 효과적으로 식별하는 데 도움이 됩니다.

  2. ABCD 패턴 매개 변수를 최적화하여 더 엄격하고 신뢰할 수 있도록 합니다.

  3. 잘못된 방향 편향을 피하기 위해 주요 트렌드 식별을 개선하십시오.

  4. 최적의 지점을 찾기 위해 다른 스톱 로스/프로피트 취합 비율을 테스트합니다.

최적화 방향

  1. 입시 신호의 정확성을 향상시키기 위해 MACD, KDJ 및 기타 지표를 테스트합니다.

  2. 다양한 제품과 시간 프레임에 기반한 매개 변수를 최적화하여 최적의 스톱 손실/이익을 얻습니다.

  3. 바 룩백 기간을 최적화하여 변화하는 시장 조건에 따라 최고의 매개 변수 조합을 찾습니다.

  4. 이동 평균 등을 추가하여 신호를 필터하고 안정성을 향상시킵니다.

  5. 기계 학습 알고리즘과 더 많은 데이터를 도입하여 패턴 인식의 정확성을 향상시킵니다.

요약

전략 논리는 전반적으로 명확하고 신뢰할 수 있으며, 윌리엄스 프랙탈 및 ABCD 패턴을 사용하여 중장기 트렌드 방향을 결정하고, 트렌드 필터링, 스톱 로스 및 수익을 취하여 트렌드를 따라 수익을 창출합니다. 입시 신호, 매개 변수 조정, 트렌드 식별 등 다양한 시장 조건에 적응할 수 있도록 최적화 할 수있는 많은 공간이 있습니다. 재량 + 양자 컴보 모델로 강력한 실용적 가치를 가지고 있습니다.


/*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)

더 많은