동력 탈출 전략

저자:차오장, 날짜: 2024-02-23 14:27:21
태그:

img

전반적인 설명

모멘텀 브레이크아웃 전략은 시장의 모멘텀을 추적하는 트렌드를 따르는 전략이다. 시장이 현재 상승 또는 하락 추세인지 판단하기 위해 여러 지표를 결합하고 주요 저항 수준을 넘어서면 긴 포지션을 개척하고 주요 지원 수준을 넘어서면 짧은 포지션을 개척합니다.

전략 논리

이 전략은 주로 시장 추세와 주요 가격 수준을 결정하기 위해 여러 시간 프레임의 돈치안 채널을 사용합니다. 구체적으로, 가격이 40 일과 같은 장기 장기 돈치안 채널의 상단 철도를 통과하면 상승 추세로 판단됩니다. 일 년 내의 새로운 최고 수준과 이동 평균의 정렬과 같은 추가 필터와 함께 긴 신호가 유발됩니다. 가격이 장기 장기 돈치안 채널의 하단 철도 아래로 넘어지면 하락 추세로 판단됩니다. 일 년 내의 새로운 최저 수준과 같은 필터와 함께 짧은 신호가 유발됩니다.

이 전략은 출구 포지션에 대해 두 가지 옵션을 제공합니다: 고정 무효 라인 및 후속 스톱 손실. 고정 무효 라인은 20 일과 같은 짧은 돈치안 채널의 하부 / 상부 레일을 사용합니다. 후속 스톱 손실은 ATR 값을 기반으로 매일 동적 스톱 손실 라인을 계산합니다. 두 방법 모두 위험을 효과적으로 제어 할 수 있습니다.

이점 분석

이 전략은 트렌드 판단과 브레이크아웃 작전을 결합하여 시장에서 단기적인 방향 기회를 효과적으로 포착 할 수 있습니다. 단일 지표와 비교하면 일부 잘못된 브레이크아웃을 필터링하고 엔트리 신호의 품질을 향상시킬 수있는 여러 필터를 사용합니다. 또한, 스톱 로스 전략의 적용은 또한 회복력을 향상시키고 시장이 잠시 후퇴하더라도 손실을 효과적으로 제어 할 수 있습니다.

위험 분석

이 전략의 주요 위험은 가격이 격렬하게 변동하여 출구 포지션에 Stop Loss를 유발할 수 있다는 것입니다. 가격이 급격히 뒤집어지면 기회를 놓칠 수 있습니다. 또한 여러 필터를 사용하면 일부 기회를 필터링하고 거래의 빈도를 줄일 수 있습니다.

위험을 줄이기 위해, ATR 곱셈을 조정하거나 도 채널 간격을 넓힐 수 있습니다. 스톱 손실이 발생할 가능성을 줄이기 위해. 일부 필터는 또한 입력 빈도를 증가시키기 위해 제거되거나 느슨해질 수 있지만 위험도 증가 할 것입니다.

최적화 방향

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

  1. 치안 채널의 길이를 최적화해서 최적의 매개 변수를 찾아내야 합니다.
  2. 다른 종류의 이동 평균을 필터로 사용해보세요.
  3. ATR 곱셈을 조정하거나 정지 손실을 위해 고정된 지점을 사용하십시오.
  4. MACD와 같은 트렌드 판단 지표를 더 추가합니다.
  5. 연중의 새로운 최고/하위 등에 대한 뷰백 기간을 최적화합니다.

다양한 매개 변수를 테스트함으로써 최적의 위험과 수익을 조정하는 조합을 찾을 수 있습니다.

결론

이 전략은 트렌드 방향을 결정하기 위해 여러 지표를 결합하고 주요 브레이크아웃 수준에서 거래를 유발합니다. 스톱 로스 메커니즘은 또한 위험에 저항력을 가집니다. 매개 변수를 최적화함으로써 안정적인 초과 수익을 얻을 수 있습니다. 시장에 대한 명확한 시각이 없지만 트렌드를 따르고 싶은 투자자에게 적합합니다.


/*backtest
start: 2024-01-23 00:00:00
end: 2024-02-22 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed

//@version=4
strategy("BuyHigh-SellLow Strategy", overlay=true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01, calc_on_order_fills = true)
donchianEntryLength = input(40, step=10)
donchianExitLength = input(20, step=10)

considerNewLongTermHighLows = input(true)
shortHighLowPeriod = input(120, step=10)
longHighLowPeriod = input(180, step=10)

considerMAAlignment = input(true)
MAType = input(title="Moving Average Type", defval="ema", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
LookbackPeriod = input(40, minval=10,step=10)

atrLength = input(22)
atrMult = input(4)

exitStrategy = input(title="Exit Strategy", defval="tsl", options=["dc", "tsl"])

considerYearlyHighLow = input(true)
backtestYears = input(10, minval=1, step=1)
f_getMovingAverage(source, MAType, length)=>
    ma = sma(source, length)
    if(MAType == "ema")
        ma := ema(source,length)
    if(MAType == "hma")
        ma := hma(source,length)
    if(MAType == "rma")
        ma := rma(source,length)
    if(MAType == "vwma")
        ma := vwma(source,length)
    if(MAType == "wma")
        ma := wma(source,length)
    ma

f_getTrailingStop(atr, atrMult)=>
    stop = close - atrMult*atr
    stop := strategy.position_size > 0 ? max(stop, stop[1]) : stop
    stop

f_getMaAlignment(MAType, includePartiallyAligned)=>
    ma5 = f_getMovingAverage(close,MAType,5)
    ma10 = f_getMovingAverage(close,MAType,10)
    ma20 = f_getMovingAverage(close,MAType,20)
    ma30 = f_getMovingAverage(close,MAType,30)
    ma50 = f_getMovingAverage(close,MAType,50)
    ma100 = f_getMovingAverage(close,MAType,100)
    ma200 = f_getMovingAverage(close,MAType,200)

    upwardScore = 0
    upwardScore := close > ma5? upwardScore+1:upwardScore
    upwardScore := ma5 > ma10? upwardScore+1:upwardScore
    upwardScore := ma10 > ma20? upwardScore+1:upwardScore
    upwardScore := ma20 > ma30? upwardScore+1:upwardScore
    upwardScore := ma30 > ma50? upwardScore+1:upwardScore
    upwardScore := ma50 > ma100? upwardScore+1:upwardScore
    upwardScore := ma100 > ma200? upwardScore+1:upwardScore
    
    upwards = close > ma5 and ma5 > ma10 and ma10 > ma20 and ma20 > ma30 and ma30 > ma50 and ma50 > ma100 and ma100 > ma200
    downwards = close < ma5 and ma5 < ma10 and ma10 < ma20 and ma20 < ma30 and ma30 < ma50 and ma50 < ma100 and ma100 < ma200
    upwards?1:downwards?-1:includePartiallyAligned ? (upwardScore > 5? 0.5: upwardScore < 2?-0.5:upwardScore>3?0.25:-0.25) : 0

//////////////////////////////////// Calculate new high low condition //////////////////////////////////////////////////
f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)=>
    newHigh = highest(shortHighLowPeriod) == highest(longHighLowPeriod) or not considerNewLongTermHighLows
    newLow = lowest(shortHighLowPeriod) == lowest(longHighLowPeriod) or not considerNewLongTermHighLows
    [newHigh,newLow]

//////////////////////////////////// Calculate Yearly High Low //////////////////////////////////////////////////
f_getYearlyHighLowCondition(considerYearlyHighLow)=>
    yhigh = security(syminfo.tickerid, '12M', high[1]) 
    ylow = security(syminfo.tickerid, '12M', low[1]) 
    yhighlast = yhigh[365]
    ylowlast = ylow[365]
    yhighllast = yhigh[2 * 365]
    ylowllast = ylow[2 * 365]
    
    yearlyTrendUp = na(yhigh)? true : na(yhighlast)? close > yhigh : na(yhighllast)? close > max(yhigh,yhighlast) : close > max(yhigh, min(yhighlast, yhighllast))
    yearlyHighCondition = (  (na(yhigh) or na(yhighlast) ? true : (yhigh > yhighlast) ) and ( na(yhigh) or na(yhighllast) ? true : (yhigh > yhighllast))) or yearlyTrendUp or not considerYearlyHighLow
    yearlyTrendDown = na(ylow)? true : na(ylowlast)? close < ylow : na(ylowllast)? close < min(ylow,ylowlast) : close < min(ylow, max(ylowlast, ylowllast))
    yearlyLowCondition = (  (na(ylow) or na(ylowlast) ? true : (ylow < ylowlast) ) and ( na(ylow) or na(ylowllast) ? true : (ylow < ylowllast))) or yearlyTrendDown or not considerYearlyHighLow
    
    label_x = time+(60*60*24*1000*1)
    [yearlyHighCondition,yearlyLowCondition]

donchian(rangeLength)=>
    upper = highest(rangeLength)
    lower = lowest(rangeLength)
    middle = (upper+lower)/2
    [middle, upper, lower]

inDateRange = true
[eMiddle, eUpper, eLower] = donchian(donchianEntryLength)
[exMiddle, exUpper, exLower] = donchian(donchianExitLength)
maAlignment = f_getMaAlignment(MAType, false)
[yearlyHighCondition, yearlyLowCondition] = f_getYearlyHighLowCondition(considerYearlyHighLow)
[newHigh,newLow] = f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)

maAlignmentLongCondition = highest(maAlignment, LookbackPeriod) == 1 or not considerMAAlignment 

atr = atr(atrLength)
tsl = f_getTrailingStop(atr, atrMult)

//U = plot(eUpper, title="Up", color=color.green, linewidth=2, style=plot.style_linebr)
//D = plot(exLower, title="Ex Low", color=color.red, linewidth=2, style=plot.style_linebr)
longCondition = crossover(close, eUpper[1]) and yearlyHighCondition and newHigh and maAlignmentLongCondition
exitLongCondition = crossunder(close, exLower[1])

shortCondition = crossunder(close, eLower[1]) and yearlyLowCondition and newLow
exitShortCondition = crossover(close, exUpper[1])
strategy.entry("Buy", strategy.long, when=longCondition and inDateRange, oca_name="oca_buy")
strategy.exit("ExitBuyDC", "Buy", when=exitStrategy=='dc', stop=exLower)
strategy.exit("ExitBuyTSL", "Buy", when=exitStrategy=='tsl', stop=tsl)
plot(strategy.position_size > 0 ? (exitStrategy=='dc'?exLower:tsl) : na, title="Trailing Stop", color=color.red, linewidth=2, style=plot.style_linebr)
//strategy.close("Buy", when=exitLongCondition)

더 많은