추세 추종 돌파 전략 기반


생성 날짜: 2024-01-22 17:21:10 마지막으로 수정됨: 2024-01-22 17:21:10
복사: 0 클릭수: 545
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

추세 추종 돌파 전략 기반

개요

이것은 트렌드 추적을 기반으로 한 돌파 전략이다. 돌파가 발생했을 때 더 강한 입력을 가진 주식을 구입하고, 돌파가 발생했을 때 더 약한 입력을 가진 주식을 판매하여 트렌드 추적을 실현한다.

전략 원칙

이 전략은 주로 두 가지 지표에 기반하여 입출소 신호를 판단합니다. 하나는 highest () 함수가 판단한 일정 기간의 최고 가격이며, 하나는 lowest () 함수가 판단한 일정 기간의 최저 가격입니다.

종결 가격이 지난 일정 주기 (변수 highPeriod) 의 최고 가격보다 높을 때, 이는 상승 추세의 돌파구로 간주되어, 따라서 더 많은 신호를 낸다. 종결 가격이 지난 일정 주기 (변수 lowPeriod) 의 최저 가격보다 낮을 때, 이는 하락 추세의 돌파구로 간주되어, 따라서 더 많은 신호를 낸다.

이 전략은 모바일 스톱로스트와 고정 스톱로스트를 동시에 설정한다. 모바일 스톱로스트는 ATR 지표에 기초하여, 일정 주기 내의 ATR 값을 계산하여, 한 배수 (변수 trailingAtrMultiplier) 로 이동 스톱로스트를 곱한다. 고정 스톱로스트도 마찬가지로 ATR 지표에 기초하여 계산된다.

더 많은 코스카이드를 한 후 첫 번째 루트 K 라인에서 고정된 스톱은 유효합니다. 이후 이동 스톱으로 전환됩니다. 이러한 조합은 트렌드를 추적하면서 일부 이익을 잠금 할 수 있습니다.

이 전략은 또한 포지션 계산 규칙을 설정한다. 최대 손실의 허용 비율, 계정 권리 이익 등에 기초하여 포지션을 계산한다. 거래 품종을 고려하여 단일 품종의 포지션을 적절히 낮추는다.

전체적으로 보면, 이것은 전형적인 트렌드 추적형 전략으로, 돌파구가 발생한다고 판단했을 때 안으로 들어가서, 스톱으로 수익을 잠금하고 트렌드를 추적하고, 트렌드가 반전될 때 밖으로 나간다.

우위 분석

이것은 획기적인 전략이며, 그 주요 장점은 다음과 같습니다.

  1. 트렌드 판단 정확함. 최고 가격과 최저 가격으로 트렌드가 반전되었는지 판단할 수 있다. 정확도가 높기 때문에 잘못된 신호를 발산하기 어렵다.

  2. 포지션 및 스톱스 과학이 합리적입니다. 최대 손실 비율을 설정하고, 계정 권리 이익 연관 등이 포지션을 합리적으로 만들고, 과잉 또는 무효 거래를 피합니다. 포지션 스톱스 방식은 이윤을 잠금하고 트렌드를 추적합니다.

  3. 간단하고 실용적이며, 사용하기 쉽다. 가장 기본적인 지표만 필요하며, 전략 논리는 간단하고 명확하며, 쉽게 습득할 수 있다.

  4. 확장성이 좋다. 지표 변수, 포지션 규칙 등이 입력 상자를 제공하여 사용자가 필요에 따라 조정할 수 있다.

전체적으로 볼 때, 이것은 매우 실용적인 돌파구 전략이다. 판단에 있어서 안전성이 높으며, 전략 설계는 위험 제어와 추적을 고려한 것이다. 중장선 보유에 매우 적합하다.

위험 분석

이 전략의 주요 위험은 다음과 같습니다.

  1. 트렌드 반전 위험. 돌파 전략은 트렌드 판단에 매우 의존하며, 잘못된 판단이 있을 경우, 엄청난 손실을 입을 수 있다.

  2. 매개 변수 위험. 최고 가격 최저 가격 주기 매개 변수 선택이 잘못되면 트렌드를 놓칠 수 있고, 포지션 매개 변수 설정이 잘못되면 손실이 너무 커질 수 있다.

  3. 너무 급진적 인 위험. 이동 중지 거리가 너무 작다면 시장 소음으로 인해 경기에서 제외 될 수 있습니다.

이 문제를 해결하기 위한 주요 해결책은 다음과 같습니다.

  1. 트렌드 필터를 추가하십시오. 예를 들어, 다른 지표 판단을 추가하여 잘못된 돌파구를 피하십시오.

  2. 최적화 변수 선택 △ 변수를 테스트하여 최적화 값을 선택하여 안정성을 보장한다 △

  3. 정지거리는 적절히 느려질 수 있다. 정지거리는 반드시 회정을 수용할 수 있다.

최적화 방향

이 전략은 다음과 같은 방향으로 최적화될 수 있습니다.

  1. 더 많은 지표 판단 트렌드를 추가하십시오. 최고 최저 가격 외에도 이동 평균과 같은 판단을 추가하여 추세를 판단하는 것이 더 정확합니다.

  2. 최적화 매개 변수 설정. 최고 최저 가격 주기 매개 변수, 스톱 로즈 배수 매개 변수 등을 테스트하여 최적의 매개 변수 조합을 선택한다.

  3. 시장 조정 포지션 알고리즘에 따라. 포지션을 시장의 변동성과 연결시킬 수 있습니다. 예를 들어, VIX가 상승하면 포지션을 줄일 수 있습니다.

  4. 양을 증가시킬 수 있는 지표 필터 . 양을 증가시킬 수 있는 돌파구에서만 들어가며, 가짜 돌파구를 피한다.

  5. 기본차와 연관성 선호 거래 품종을 고려하십시오. 기본차 변동이 작고 연관성이 낮은 품종 조합을 선택하면 포지션 위험을 줄일 수 있습니다.

  6. 최적화 및 조정 스톱 메커니즘. 이동 스톱과 고정 스톱의 비율 조합을 테스트하여 너무 급진적인 스톱의 위험을 줄일 수 있습니다.

요약하다

이 전략은 트렌드 추적형의 돌파구 전략으로 판단 정확성, 포지션 및 위험 제어, 조작 단순성 등에서 좋은 성과를 냈다. 그것은 트렌드의 초기기를 캡처하고, 이동식 스톱로스로 수익의 잠금과 트렌드 추적을 균형을 잡았다.

물론 돌파구 전략으로서, 트렌드 판단에 대한 의존도가 매우 높으며, 노이즈의 방해에 취약하다. 또한, 파라미터 설정이 적절하지 않은 것도 전략의 성능에 영향을 줄 수 있다. 이것은 추가적인 최적화를 통해 해결해야 한다.

전체적으로 볼 때, 이것은 매우 실용적인 전략이며, 그것의 기본 구조는 이미 정량화 전략이 필요로 하는 가장 중요한 요소를 포함하고 있다. 계속적으로 최적화하고 개선할 수 있다면, 안정적으로 수익을 창출하는 프로그램화 전략이 될 수 있다.

전략 소스 코드
/*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(shorttitle="Trend Surfers - Breakout", title="Trend Surfers - Premium Breakout",
     overlay=true)

// Risk for position and pyramid
maxriskval = input(2, "Max % risk", type = input.float,
     tooltip="Risk % over total equity / Position", group = "Risk Management")
pairnumber = input(title = "How many pairs",type = input.integer, defval= 1,
     tooltip="How many pairs are you trading with the strategy?", group = "Risk Management")

// Emtry Exit
highPeriod = input(title="Highest High Period", type=input.integer, defval=168
     , tooltip="Highest High of X bars - This will trigger a Long Entry when close is above. (Thin Green Line)"
     , group = "Entry Condition")
lowPeriod = input(title="Lowest Low Period", type=input.integer, defval=168,
     tooltip="Lowest low of X bars - This will trigger a Short Entry when close is under. (Thin Red Line)"
     , group = "Entry Condition")
// Stoploss
trailingAtrPeriod = input(title="Trailing ATR Pediod", type=input.integer, defval=10,
     tooltip="Average True Range for the Trailing Stop. (Thick Green Line) "
     , group = "Exit Condition")
trailingAtrMultiplier = input(title="Trailing ATR Multiplier", type=input.float, defval=8
     , group = "Exit Condition")
fixAtrPeriod = input(title="Fix ATR Pediod", type=input.integer, defval=10,
     tooltip="Average True Range for the Fix Stoloss. (Thick Yellow Line)"
     , group = "Exit Condition")
fixAtrMultiplier = input(title="Fix ATR Multiplier", type=input.float, defval=2
     , group = "Exit Condition")
// Pair info 
pair = syminfo.basecurrency + syminfo.currency

// High Low Variable
highestHigh = highest(high, highPeriod)[1]
lowestLow = lowest(low, lowPeriod)[1]
trailingAtr = atr(trailingAtrPeriod) * trailingAtrMultiplier

// Trade Condition
longCondition = crossover(close, highestHigh) 
shortCondition = crossunder(close, lowestLow)

// Risk Variable
fixAtr = atr(fixAtrPeriod) * fixAtrMultiplier
stopvaluelong = close[1] - fixAtr[1]
stopvalueshort = close[1] + fixAtr[1]

// Position size Long
maxpossize = strategy.equity / close 
positionsizelong = ( ( ( (maxriskval/100) * strategy.equity) / (close - stopvaluelong))) 
stopperclong = ((close - stopvaluelong) / close) * 100
leveragelong = max(1, ceil(positionsizelong / maxpossize)) * 2
posperclong =  (((positionsizelong * close) / strategy.equity) *100 / leveragelong) / pairnumber
realposlong = (((posperclong / 100) * strategy.equity) * leveragelong) / close

// Position size Short
positionsizeshort = ( ( ( (maxriskval/100) * strategy.equity) / (stopvalueshort - close))) 
stoppercshort = ((close - stopvalueshort) / close) * 100
leverageshort = max(1, ceil(positionsizeshort / maxpossize)) * 2
pospercshort =  (((positionsizeshort * close) / strategy.equity) *100 / leverageshort) / pairnumber
realposshort = (((pospercshort / 100) * strategy.equity) * leverageshort) / close

// Alert Message
entry_long_message = '\nGo Long for ' + pair + 'NOW!' +
                     '\nPosition Size % =' + tostring(posperclong) +
                     '\nLeverage' + tostring(leveragelong) +
                     '\nStoploss Price =' + tostring(stopvaluelong) +
                     '\nClose any Short position that are open for ' + pair + '!' +
                     '\n\nVisit TrendSurfersSignals.com' +
                     '\nFor automated premium signals (FREE)'

entry_short_message ='\nGo Short for ' + pair + 'NOW!' +
                     '\nPosition Size % =' + tostring(pospercshort) +
                     '\nLeverage' + tostring(leverageshort) +
                     '\nStoploss Price =' + tostring(stopvalueshort) +
                     '\nClose any Long position that are open for ' + pair + '!' +
                     '\n\nVisit TrendSurfersSignals.com' +
                     '\nFor automated premium signals (FREE)'

exit_short_message = '\nExit Short for ' + pair + 'NOW!' +
                     '\n\nVisit TrendSurfersSignals.com' +
                     '\nFor automated premium signals (FREE)'

exit_long_message = '\nExit Long for ' + pair + 'NOW!' +
                     '\n\nVisit TrendSurfersSignals.com' +
                     '\nFor automated premium signals (FREE)'
// Order
if longCondition 
    strategy.entry("Long", strategy.long, stop=highestHigh, comment="Long", qty=realposlong
     , alert_message = entry_long_message)
if shortCondition
    strategy.entry("Short", strategy.short, stop=lowestLow, comment="Short", qty=realposshort
     , alert_message = entry_short_message)

// Stoploss Trailing
longTrailing = close - trailingAtr
shortTrailing = close + trailingAtr

var longTrailingStop = 0.0
var shortTrailingStop = 999999.9

trailingStopLine = 0.0
trailingStopLine := na
fixedStopLine = 0.0
fixedStopLine := na
var inTrade = 0
if longCondition or shortCondition
    if 0 == inTrade
        if longCondition
            inTrade := 1
        else
            inTrade := -1
if 1 == inTrade and (shortCondition or low <= max(fixedStopLine[1], longTrailingStop))
    inTrade := 0
if -1 == inTrade and (longCondition or high >= min(fixedStopLine[1], shortTrailingStop))
    inTrade := 0

longTrailingStop := if (1 == inTrade)
    stopValue = longTrailing
    max(stopValue, longTrailingStop[1])
else
    0

shortTrailingStop := if (-1 == inTrade)
    stopValue = shortTrailing
    min(stopValue, shortTrailingStop[1])
else
    999999

// Fix Stoploss
firstPrice = 0.0
firstFixAtr = 0.0
firstPrice := na
firstFixAtr := na
if 0 != inTrade
    firstPrice := valuewhen(inTrade != inTrade[1] and 0 != inTrade, close, 0)
    firstFixAtr := valuewhen(inTrade != inTrade[1] and 0 != inTrade, fixAtr, 0)
    if 1 == inTrade
        fixedStopLine := firstPrice - firstFixAtr
        trailingStopLine := longTrailingStop
    else
        fixedStopLine := firstPrice + firstFixAtr
        trailingStopLine := shortTrailingStop

if (strategy.position_size > 0)
    strategy.exit(id="L Stop", stop=max(fixedStopLine, longTrailingStop)
     , alert_message = exit_long_message)

if (strategy.position_size < 0)
    strategy.exit(id="S Stop", stop=min(fixedStopLine, shortTrailingStop)
     , alert_message = exit_long_message)
    

// Plot
plot(highestHigh, color=color.green, linewidth=1, transp=0, title='Highest High')
plot(lowestLow, color=color.red, linewidth=1, transp=0, title='Lowest Low')
plot(trailingStopLine, color=color.lime, linewidth=2, transp=0, offset=1, title='Trailing Stop')
plot(fixedStopLine, color=color.orange, linewidth=2, transp=0, offset=1, title='Fixed Stop')