모멘텀 ABCD 패턴 전략


생성 날짜: 2023-09-24 13:08:28 마지막으로 수정됨: 2023-09-24 13:08:28
복사: 1 클릭수: 736
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 윌리엄스 프랙탈 지표를 사용하여 가격의 높고 낮은 지점을 식별하고 ABCD 형태와 결합하여 트렌드 방향을 판단하고, 트렌드가 확인된 후 입장을 취하여 짧은 선의 트렌드를 추적하여 수익을 얻습니다.

전략 원칙

  1. 윌리엄스 프랙탈 지표를 사용하여 가격의 높고 낮은 지점을 식별하고, 다른 형태에 따라 황소 시장의 ABCD 형태 또는 곰 시장의 ABCD 형태로 판단한다.

  2. ABCD 형태 판단 기준:

    • AB와 CD 사이의 거리는 가깝고, BC와 CD 사이의 거리는 일정 비율 요구 사항을 충족한다 ((0.382-0.886과 1.13-2.618 사이에) )

    • D점보다 낮은 C점은 황소 시장 형태이고, D점보다 높은 C점은 곰 시장 형태이다.

  3. barssince 함수를 통해 전 방향의 Fractal 거리가 현재 가장 근접한 것을 판단하여 현재 전체 경향 방향을 판단한다.

  4. ABCD 형태를 인식할 때 더 많은/더 적은 것을 입력하고, 단축선 트렌드를 추적하기 위해 스톱 및 스톱을 설정합니다.

전략적 강점 분석

  1. 윌리엄스 프랙탈 지표 보조 판단을 사용하여 전환점을 더 정확하게 식별 할 수 있습니다.

  2. ABCD 형태 판단 기준은 간단하고 신뢰할 수 있으며, 프로그래밍이 쉽다.

  3. barssince 함수와 결합하여 큰 트렌드 방향을 판단하여 가짜 돌파구로 인한 손실을 효과적으로 줄일 수 있습니다.

  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)