다중 기간 슈퍼 트렌드 동적 피라미드 거래 전략

ATR ST SL
생성 날짜: 2025-01-06 17:02:35 마지막으로 수정됨: 2025-01-06 17:02:35
복사: 0 클릭수: 460
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

다중 기간 슈퍼 트렌드 동적 피라미드 거래 전략

개요

이는 여러 가지 Supertrend 지표를 기반으로 한 피라미드 거래 전략입니다. Supertrend 지표를 세 가지 다른 기간과 배수로 설정하여 확률이 높은 거래 기회를 식별합니다. 이 전략은 동적 피라미드 포지션 추가 방법을 채택하고, 최대 3개의 진입을 허용하며, 동적 손절매와 유연한 종료 조건을 결합하여 수익 극대화와 위험 관리를 달성합니다.

전략 원칙

이 전략은 빠름, 보통, 느림의 세 가지 매개변수 설정을 갖춘 Supertrend 지표를 사용합니다. 진입 신호는 이 세 가지 지표의 교차점과 추세 방향을 기반으로 하며, 포지션을 추가하기 위해 3층 피라미드 스타일을 사용합니다. 첫 번째 층은 빠른 지표가 하락하고 중간 지표가 상승하며 느린 지표가 상승할 때 시장에 진입합니다. 지표가 하향하고 있습니다. 두 번째 계층은 빠른 지표가 상향할 때 시장에 진입합니다. 중속 지표와 중속 지표가 함께 하향할 때 돌파를 통해 시장에 진입합니다. 세 번째 수준은 돌파를 통해 시장에 진입하는 것입니다. 시장이 새로운 최고가에 도달하면 돌파구가 생깁니다. 종료는 동적 손절매, 평균 가격 손절매, 전체 추세 반전 등 다양한 메커니즘을 채택합니다.

전략적 이점

  1. 다중 확인 메커니즘으로 거래 정확도 향상
  2. 피라미딩은 추세 시장에서 수익을 크게 늘릴 수 있습니다.
  3. 동적 손절매 메커니즘은 수익을 보호하는 동시에 추세가 발전할 수 있는 충분한 여지를 제공합니다.
  4. 유연한 종료 메커니즘은 다양한 시장 환경에 더 잘 대처할 수 있습니다.
  5. 다양한 펀드 규모에 맞게 퍼센트 포지션 제어를 활용하세요

전략적 위험

  1. 변동성이 큰 시장에서는 잘못된 신호가 자주 발생할 수 있습니다.
  2. 피라미딩은 추세가 갑자기 반전될 때 더 큰 하락으로 이어질 수 있습니다.
  3. 여러 지표로 인해 신호 지연이 발생할 수 있습니다.
  4. 매개변수 최적화에는 과적합의 위험이 있습니다. 이러한 위험을 통제하기 위해 엄격한 자금 관리와 백테스팅을 실시하는 것이 좋습니다.

전략 최적화 방향

  1. 다양한 변동성 환경에서 매개변수를 동적으로 조정하기 위해 시장 환경 필터링 메커니즘을 추가합니다.
  2. 포지션 추가 간격과 포지션 할당 비율을 최적화합니다.
  3. 거짓 신호를 걸러내기 위해 더 많은 기술적 지표 도입
  4. 시장 변화에 적응하기 위한 적응형 매개변수 메커니즘 개발
  5. 종료 메커니즘을 개선하고 이익 목표 및 시간 정지 손실 추가를 고려할 수 있습니다.

요약하다

이 전략은 여러 가지 슈퍼트렌드 지표와 피라미드 추가 방식을 통해 트렌드 기회를 포착하고, 역동적인 손절매와 유연한 종료 메커니즘을 통해 위험을 통제합니다. 일정한 한계는 있지만, 지속적인 최적화와 엄격한 위험 관리를 통해 이 전략은 좋은 실용적 적용 가치를 가지고 있습니다.

전략 소스 코드
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=6
strategy('4Vietnamese 3x Supertrend', overlay=true, max_bars_back=1000, initial_capital = 10000000000, slippage = 2, commission_type = strategy.commission.percent, commission_value = 0.013, default_qty_type=strategy.percent_of_equity, default_qty_value = 33.33, pyramiding = 3, margin_long = 0, margin_short = 0)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Inputs

// Supertrend Settings
STATRLENGTH1 = input.int(10, title='Fast Supertrend ATR Length', group='SUPERTREND SETTINGS')
STATRMULT1 = input.float(1, title='Fast Supertrend ATR Multiplier', group='SUPERTREND SETTINGS')
STATRLENGTH2 = input.int(11, title='Medium Supertrend ATR Length', group='SUPERTREND SETTINGS')
STATRMULT2 = input.float(2, title='Medium Supertrend ATR Multiplier', group='SUPERTREND SETTINGS')
STATRLENGTH3 = input.int(12, title='Slow Supertrend ATR Length', group='SUPERTREND SETTINGS')
STATRMULT3 = input.float(3, title='Slow Supertrend ATR Multiplier', group='SUPERTREND SETTINGS')

isUseHighestOf2RedCandleSetup = input.bool(false, group = "Setup Filters")


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Calculations 
[superTrend1, dir1] = ta.supertrend(STATRMULT1, STATRLENGTH1)
[superTrend2, dir2] = ta.supertrend(STATRMULT2, STATRLENGTH2)
[superTrend3, dir3] = ta.supertrend(STATRMULT3, STATRLENGTH3)

// directionST1 = dir1 == 1 and dir1[1] == 1 ? false : dir1 == -1 and dir1[1] == -1 ? true : false
// directionST2 = dir2 == 1 and dir2[1] == 1 ? false : dir2 == -1 and dir2[1] == -1 ? true : false
// directionST3 = dir3 == 1 and dir3[1] == 1 ? false : dir3 == -1 and dir3[1] == -1 ? true : false


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Calculate highest from supertrend1 uptrend
var float highestGreen = 0
if dir1 < 0 and highestGreen == 0 and (isUseHighestOf2RedCandleSetup ? close < open : true)
    highestGreen := high
if highestGreen > 0 and (isUseHighestOf2RedCandleSetup ? close < open : true)
    if high > highestGreen
        highestGreen := high
if dir1 >= 0
    highestGreen := 0


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Entry SL
var entrySL4Long1 = false
var entrySL4Long2 = false
var entrySL4Long3 = false

isUseEntrySL = input.bool(true, group = "Entry SL Option")
dataToCalculate = input.source(low, group = "Entry SL Option")

if isUseEntrySL and (dir1 > 0 and dir2 < 0 and dir3 < 0)
    if strategy.opentrades >= 1
        if dataToCalculate > strategy.opentrades.entry_price(0)
            entrySL4Long1 := true
        else 
            entrySL4Long1 := false

        if entrySL4Long1 and close > strategy.opentrades.entry_price(0)
            strategy.exit('exit1', from_entry = 'long1', stop = strategy.opentrades.entry_price(0))

    if strategy.opentrades >= 2 
        if dataToCalculate > strategy.opentrades.entry_price(1)
            entrySL4Long2 := true
        else 
            entrySL4Long2 := false
    
        if entrySL4Long2 and close > strategy.opentrades.entry_price(1)
            strategy.exit('exit2', from_entry = 'long2', stop = strategy.opentrades.entry_price(1))   

    if strategy.opentrades >= 3 
        if dataToCalculate > strategy.opentrades.entry_price(2) 
            entrySL4Long3 := true
        else 
            entrySL4Long3 := false
    
        if entrySL4Long3 and close >  strategy.opentrades.entry_price(2)
            strategy.exit('exit3', from_entry = 'long3', stop = strategy.opentrades.entry_price(2))

if strategy.closedtrades > strategy.closedtrades[1]
    if strategy.closedtrades.exit_id(strategy.closedtrades-1) == 'exit3'
        entrySL4Long3 := false
    if strategy.closedtrades.exit_id(strategy.closedtrades-1) == 'exit2'
        entrySL4Long2 := false
    if strategy.closedtrades.exit_id(strategy.closedtrades-1) == 'exit1'
        entrySL4Long1 := false

    
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Entry
if dir3 < 0
    if dir2 > 0 and dir1 < 0
        strategy.entry('long1', strategy.long)
    else if dir2 < 0
        strategy.entry('long2', strategy.long, stop=superTrend1)
else
    if dir1 < 0 and highestGreen > 0
        strategy.entry('long3', strategy.long, stop=highestGreen)


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Exit
isUseAllDowntrendExit = input.bool(true, group = "Exit Type")
if isUseAllDowntrendExit and dir3 > 0 and dir2 > 0 and dir1 > 0 and close < open
    strategy.close_all()

isUseAvgPriceInLoss = input.bool(true, group = "Exit Type")
if isUseAvgPriceInLoss and strategy.position_avg_price > close //and strategy.position_avg_price <= close[1]
    //  and (dir1 > 0 or dir2 > 0 or dir3 > 0)
    //  and strategy.opentrades >= 1  
    //  and strategy.opentrades >= 3  
    strategy.close_all()

isUseAllPositionsInLoss = input.bool(false, group = "Exit Type")
if isUseAllPositionsInLoss
      and (
       false
         or (strategy.opentrades == 1 and ((not na(strategy.opentrades.entry_price(0))) and strategy.opentrades.entry_price(0) > close))

         or (strategy.opentrades == 1 and ((not na(strategy.opentrades.entry_price(0))) and strategy.opentrades.entry_price(0) > close)
             and ((not na(strategy.opentrades.entry_price(1))) and strategy.opentrades.entry_price(1) > close))

         or (strategy.opentrades == 1 and ((not na(strategy.opentrades.entry_price(0))) and strategy.opentrades.entry_price(0) > close)
             and ((not na(strategy.opentrades.entry_price(1))) and strategy.opentrades.entry_price(1) > close)
             and ((not na(strategy.opentrades.entry_price(2))) and strategy.opentrades.entry_price(2) > close))
         )
    strategy.close_all()


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Plot
plot(superTrend1, title='Fast Supertrend',      color=dir1 == 1 and dir1[1] == 1 ? color.red : dir1 == -1 and dir1[1] == -1 ? color.green : na)
plot(superTrend2, title='Medium Supertrend',    color=dir2 == 1 and dir2[1] == 1 ? color.red : dir2 == -1 and dir2[1] == -1 ? color.green : na)
plot(superTrend3, title='Slow Supertrend',      color=dir3 == 1 and dir3[1] == 1 ? color.red : dir3 == -1 and dir3[1] == -1 ? color.green : na)