트리플 슈퍼트렌드 브레이크업 전략

저자:차오장, 날짜: 2023-12-21 12:05:07
태그:

img

전반적인 설명

트리플 슈퍼트렌드 브레이크아웃 전략 (Triple Supertrend Breakout Strategy) 은 트렌드 방향과 거래를 식별하기 위해 다양한 매개 변수 설정과 트렌드 정의 EMA를 가진 여러 슈퍼트렌드 라인을 활용하는 일반적으로 사용되는 전략이다. 이 전략의 주요 아이디어는 적어도 두 개의 슈퍼트렌드 라인이 트렌드 정의 EMA 라인 위에 상승 추세를 보이는 경우 긴 포지션을 설정하고, 적어도 두 개의 슈퍼트렌드 라인이 트렌드 정의 EMA 라인 아래에 하락 추세를 보이는 경우 짧은 포지션을 설정하는 것입니다.

전략 원칙

이 전략은 다른 매개 변수를 가진 세 개의 슈퍼 트렌드 라인과 진입 및 출구를 결정하는 주요 트렌드를 정의하는 EMA 라인을 사용합니다.

  1. 세 개의 슈퍼트렌드 라인을 설정합니다. 슈퍼트렌드1, 슈퍼트렌드2, 슈퍼트렌드3, 녹색은 상승 추세를 나타내고 빨간색은 하락 추세를 나타냅니다.

  2. 주요 트렌드를 정의하기 위해 EMA 라인 에메트렌드를 설정합니다. 세 개의 슈퍼 트렌드 라인이 이 EMA 위에 있을 때 시장은 상승 추세로 정의되며, 그 반대의 경우 하락 추세로 정의됩니다.

  3. 적어도 두 개의 슈퍼트렌드 라인이 주요 상승 추세 시장의 조건에서 동시에 상승 추세를 보이는 경우 (녹색), 즉 방향 값이 0보다 작을 경우, 그것은 긴 신호로 판단됩니다. 적어도 두 개의 슈퍼트렌드 라인이 주요 하락 추세 시장의 조건에서 동시에 하락 추세를 보이는 경우 (붉은), 즉 방향 값이 0보다 크면, 그것은 짧은 신호로 판단됩니다.

  4. 그 후 신호가 발사되면 긴/단순 포지션을 개척합니다.

  5. 스톱 로스 및 영업 조건 설정. 고정 스톱 로스 수익은 3의 위험/이익 비율로 설정됩니다. 후속 스톱 로스는 1 ATR의 하락으로 설정됩니다.

  6. 스톱 로스 또는 영업 조건이 발생하면 포지션을 닫습니다.

이점 분석

이 전략의 장점은 다음과 같습니다.

  1. 세 개의 슈퍼트렌드 라인을 트렌드 판단 EMA와 결합하면 트렌드 신호를 효과적으로 식별 할 수 있습니다.

  2. 긴 조건과 짧은 조건은 명확하고 이해하기 쉽고 실행하기 쉽습니다.

  3. 트레일링 스톱 로스 및 고정 프리 설정은 위험을 효과적으로 관리합니다.

  4. 하이퍼 매개 변수는 전략을 최적화하기 위해 필요에 따라 조정할 수 있습니다.

위험 분석

이 전략에는 몇 가지 위험도 있습니다.

  1. 부적절한 매개 변수 설정은 좋은 거래 기회를 놓칠 수 있습니다. 다른 기간, ATR의 배수 및 EMA의 기간을 테스트 할 수 있습니다.

  2. 실패할 확률이 있습니다. 매개 변수를 조정하면 감소할 수 있습니다.

  3. 스톱 로스 또는 취익 설정이 너무 넓으면 손실 확률이 증가 할 수 있습니다. 스톱 로스 범위는 적절히 강화되어야합니다.

  4. 백테스트 데이터는 쉽게 과장 문제로 이어질 수 있습니다. 여러 시장, 여러 시간 프레임 테스트를 참고해야합니다.

최적화 방향

이 전략을 최적화 할 수있는 몇 가지 방법:

  1. 최적의 매개 변수 조합을 테스트하십시오. ATR 기간, 곱하기 및 EMA 기간의 다양한 조합을 테스트하여 가장 좋은 것을 찾을 수 있습니다.

  2. 거래 종류를 늘려 주식, 암호화폐 등을 추가하여 시장에서 효과를 테스트할 수 있습니다.

  3. 신호 필터링을 위해 다른 지표와 결합합니다. 예를 들어, RSI, MACD 등을 추가하여 트렌드 신호를 잘못 읽는 것을 피할 수 있습니다.

  4. 스톱 로스를 최적화하고 이윤을 취하는 메커니즘. ATR / 변동성의 변화에 따라 트레이링 스톱 로스 또는 스톱 로스를 테스트 할 수 있습니다.

결론

요약하자면, 트리플 슈퍼트렌드 브레이크아웃 전략은 비교적 간단하고 실용적인 트렌드 다음 전략이다. 여러 개의 슈퍼트렌드 라인과 트렌드 판단 EMA를 결합하여 기회를 발견하고 위험을 효과적으로 관리한다. 매개 변수 및 논리 최적화를 통해 더 나은 결과를 얻을 수 있다. 이 전략은 이해하기 쉽고 배울 가치가 있다.


/*backtest
start: 2022-12-14 00:00:00
end: 2023-12-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=5
// author=theasgard and moonshot-indicator (ms)
// year 2021
//
// This is a well knowen strategy by using 3 different Supertrends and a trend-defining EMA,
// feel free to play around with the settings, a backtest on 8h ETHUSDT pair brought some good results using 
// the 233EMA and investing 75% of a 10k start capital
//
// the idea is to have at least 2 supertrnds going green above the trend-EMA to go long and exit by turning 
// 2 supertrends red (idea: 1 supertrend in red could initialize a take profit)
// shorts work vice versa
// The EMA shows in green for uptrends and in red for downtrends, if it is blue no Signal will be taken because 
// the 3 supertrends are not all above or below the trendline(EMA)
//
// Update 1:
// Fixed a minor input error
// Added ATR stoploss, and commented out the percentage stop loss
// Added time window to backtest
// Added exit on risk/revard is met
// This version is only buy...wait for next update adding shorts

strategy("ms hypertrender", overlay=true)

// set up 3 supertrendlines and colour the direction up/down
atrPeriod1 = input(10, "ATR Length 1")
factor1 = input.float(1.0, "ATR Factor 1", step = 0.01)
[supertrend1, direction1] = ta.supertrend(factor1, atrPeriod1)
upTrend1 = plot(direction1 < 0 ? supertrend1 : na, "Up Trend 1", color = color.green, style=plot.style_linebr)
downTrend1 = plot(direction1 < 0? na : supertrend1, "Down Trend 1", color = color.red, style=plot.style_linebr)

atrPeriod2 = input(11, "ATR Length 2")
factor2 = input.float(2.0, "ATR Factor 2", step = 0.01)
[supertrend2, direction2] = ta.supertrend(factor2, atrPeriod2)
upTrend2 = plot(direction2 < 0 ? supertrend2 : na, "Up Trend 2", color = color.green, style=plot.style_linebr)
downTrend2 = plot(direction2 < 0? na : supertrend2, "Down Trend 2", color = color.red, style=plot.style_linebr)

atrPeriod3 = input(12, "ATR Length 3")
factor3 = input.float(3.0, "ATR Factor 3", step = 0.01)
[supertrend3, direction3] = ta.supertrend(factor3, atrPeriod3)
upTrend3 = plot(direction3 < 0 ? supertrend3 : na, "Up Trend 3", color = color.green, style=plot.style_linebr)
downTrend3 = plot(direction3 < 0? na : supertrend3, "Down Trend 3", color = color.red, style=plot.style_linebr)

//set up the trend dividing EMA and color uptrend nutreal downtrend
len = input.int(233, minval=1, title="Trend-EMA Length")
src = input(close, title="Source")
offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)

//general Bull or Bear Trend? Visualized by ema
ematrend = ta.ema(src, len)
generaluptrend = supertrend1 > ematrend and supertrend2 > ematrend and supertrend3 > ematrend
generaldowntrend = supertrend1 < ematrend and supertrend2 < ematrend and supertrend3 < ematrend
emacolor = if generaluptrend
    color.green
else if generaldowntrend
    color.red
else
    color.blue
plot(ematrend, title="EMA", color=emacolor, linewidth=3, offset=offset)

// Bullish? min 2 supertrends green
bullish = (direction1 < 0 and direction2 < 0) or (direction1 < 0 and direction3 < 0) or (direction2 < 0 and direction3 < 0) and generaluptrend
extremebullish = direction1 < 0 and direction2 < 0 and direction3 < 0 and generaluptrend //all 3 green

// Bearish? min 2 supertrends red
bearish = (direction1 > 0 and direction2 > 0) or (direction1 > 0 and direction3 > 0) or (direction2 > 0 and direction3 > 0) and generaldowntrend
extremebearish = direction1 > 0 and direction2 > 0 and direction3 > 0 and generaldowntrend //all 3 red

// Open Long
//plotchar(((bullish and not bullish[1]) or (extremebullish and not extremebullish[1])) and (emacolor==color.green)? close : na, title = 'Start Long', char='▲', color = #80eb34, location = location.belowbar, size = size.small)

// TP 10% Long
TP10long = ((generaluptrend and bullish[1]) or (generaluptrend and extremebullish[1])) and (direction1 > 0 or direction2 > 0 or direction3 > 0)
//plotchar(TP10long and not TP10long[1]? close : na, title = 'TP on Long', char='┼', color = #ffd000, location = location.abovebar, size = size.tiny)

// Exit Long
//plotchar(extremebearish and not extremebearish[1] or bearish and not bearish[1]? close : na, title = 'Close all Longs', char='Ꭓ', color = #ff0037, location = location.abovebar, size = size.tiny)
stopsupertrendup = if supertrend1 < supertrend2 and supertrend1 < supertrend3
    (supertrend1)
else if supertrend2 < supertrend1 and supertrend2 < supertrend3
    (supertrend2)
else if supertrend3 < supertrend1 and supertrend3 < supertrend2
    (supertrend3)
lowestLows = ta.lowest(low, 1)
// Open Short
//plotchar(((bearish and not bearish[1]) or (extremebearish and not extremebearish[1])) and (emacolor==color.red)? close : na, title = 'Start Short', char='▼', color = #0547e3, location = location.abovebar, size = size.small)

// TP 10% Short
TP10short = ((generaldowntrend and bearish[1]) or (generaldowntrend and extremebearish[1])) and (direction1 < 0 or direction2 < 0 or direction3 < 0)
//plotchar(TP10short and not TP10short[1]? close : na, title = 'TP on Short', char='┼', color = #ffd000, location = location.belowbar, size = size.tiny)

// Exit Short
//plotchar(extremebullish and not extremebullish[1] or bullish and not bullish[1]? close : na, title = 'Close all Shorts', char='Ꭓ', color = #ff0037, location = location.belowbar, size = size.tiny)
stopsupertrenddown = if supertrend1 > supertrend2 and supertrend1 > supertrend3
    (supertrend1)
else if supertrend2 > supertrend1 and supertrend2 > supertrend3
    (supertrend2)
else if supertrend3 > supertrend1 and supertrend3 > supertrend2
    (supertrend3)
highestHighs = ta.highest(high,1)
// Set stop loss level with input options (optional)
//longLossPerc = input.float(title="Long Stop Loss (%)",
//     minval=0.0, step=0.1, defval=1) * 0.01

//shortLossPerc = input.float(title="Short Stop Loss (%)",
//     minval=0.0, step=0.1, defval=1) * 0.01
     
// Determine stop loss price
//longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)
//shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)

openlong = (extremebullish and not extremebullish[1]) and (emacolor==color.green)//(((bullish and not bullish[1]) or 
openshort = (extremebearish and not extremebearish[1]) and (emacolor==color.red)//(((bearish and not bearish[1]) or 
exitlong = lowestLows<(stopsupertrendup - ((stopsupertrendup / 100) * 0.1)) //(extremebearish and not extremebearish[1] or bearish and not bearish[1]) or TP10long or 
exitshort = highestHighs>(stopsupertrenddown - ((stopsupertrenddown / 100) * 0.1)) //(extremebullish and not extremebullish[1] or bullish and not bullish[1]) or TP10short
//strategy.entry("buy", strategy.long, when=openlong)
//strategy.entry("sell", strategy.short, when=openshort)

//strategy.close("buy", when=exitlong)
//strategy.close("sell", when=exitshort)

// Submit exit orders based on calculated stop loss price
//if (strategy.position_size > 0)
//    strategy.exit(id="Long Stop", stop=longStopPrice)

//if (strategy.position_size < 0)
//    strategy.exit(id="Short Stop", stop=shortStopPrice)

backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time")
USE_ENDTIME = input(false,title="Define the ending period for backtests (If false, will test up to most recent candle)")
backtest_timeframe_end = input(defval = timestamp("19 Mar 2021 19:30 +0000"), title = "Backtest End Time")
TARGET_PROFIT_MODE = input(false,title="Exit when Risk:Reward met")
REWARD_RATIO = input(3,title="Risk:[Reward] (i.e. 3) for exit")
// Trailing stop loss {
TSL_ON = input(true,title="Use trailing stop loss")
var entry_price = float(0)
ATR_multi_len = 26
ATR_multi = input(2, "ATR multiplier for stop loss")
ATR_buffer = ta.atr(ATR_multi_len) * ATR_multi
plotchar(ATR_buffer, "ATR Buffer", "A", location = location.top)
risk_reward_buffer = (ta.atr(ATR_multi_len) * ATR_multi) * REWARD_RATIO
take_profit_long = low > entry_price + risk_reward_buffer
take_profit_short = low < entry_price - risk_reward_buffer
var trailing_SL_buffer = float(0)
var stop_loss_price = float(0)
stop_loss_price := math.max(stop_loss_price, close - trailing_SL_buffer)
// plot TSL line
trail_profit_line_color = color.green
if strategy.position_size == 0  or not TSL_ON
    trail_profit_line_color := color.black
    stop_loss_price := close - trailing_SL_buffer
plot(stop_loss_price,color=trail_profit_line_color)
// }

if true
    buy_condition = openlong
    exit_condition = exitlong
    //ENTRY:
    if buy_condition
        if strategy.position_size == 0
            entry_price := close
            trailing_SL_buffer := ATR_buffer
            stop_loss_price := close - ATR_buffer
        
        msg = "entry"
        if strategy.position_size > 0
            msg := "pyramiding"
        strategy.entry("Long",strategy.long, comment=msg)

    //EXIT:
    // Case (A) hits trailing stop
    if TSL_ON and strategy.position_size > 0 and close <= stop_loss_price
        if close > entry_price
            strategy.close("Long", comment="take profit [trailing]")
        else if close <= entry_price 
            strategy.close("Long", comment="stop loss")
    // Case (B) take targeted profit relative to risk 
    if strategy.position_size > 0 and TARGET_PROFIT_MODE
        if take_profit_long
            strategy.close("Long", comment="take profits [risk:reward]")
    // Case (C)
    if strategy.position_size > 0 and exit_condition
        if take_profit_long
            strategy.close("Long", comment="exit[rsi]")

더 많은