다중 시간대 슈퍼트렌드 트렌드 트레이딩 전략의 동적 조합 알고리즘

ATR MTF EMA RSI
생성 날짜: 2025-01-06 16:38:12 마지막으로 수정됨: 2025-01-06 16:38:12
복사: 2 클릭수: 482
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

다중 시간대 슈퍼트렌드 트렌드 트레이딩 전략의 동적 조합 알고리즘

개요

이 전략은 다중 시간대 슈퍼트렌드 지표를 기반으로 한 적응형 추세 추종 시스템입니다. 3가지 다른 시간대(15분, 5분, 2분)의 Supertrend 신호를 통합하여 포괄적인 트렌드 식별 프레임워크를 구축합니다. 이 전략은 시간 필터를 사용하여 가장 활발한 거래 시간에만 실행되도록 하고, 당일 거래 종료 시 자동으로 포지션을 마감하여 당일 위험을 방지합니다.

전략 원칙

전략의 핵심은 여러 기간 동안의 추세 일관성을 통해 거래 신호를 확인하는 것입니다. 구체적으로:

  1. 슈퍼트렌드 선은 ATR 기간과 배수를 사용하여 각 기간에 대해 계산됩니다.
  2. 세 가지 시간 단위 모두에서 강세 신호가 나타나면(가격이 슈퍼트렌드 선 위에 있는 경우) 매수로 전환됩니다.
  3. 매도는 가격이 5분 슈퍼트렌드선 아래로 떨어지거나 거래일 종료 시점에 도달할 때 발생합니다.
  4. 시간대와 거래 세션 필터(기본값 09:30-15:30)를 설정하여 거래 시간을 제어하세요.

전략적 이점

  1. 다차원적 추세 확인은 신호의 신뢰성을 높이고 거짓 돌파의 위험을 효과적으로 줄입니다.
  2. 적응형 슈퍼트렌드 매개변수 설정을 통해 다양한 시장 변동성 환경에 맞춰 전략을 조정할 수 있습니다.
  3. 엄격한 시간 관리 메커니즘을 통해 비효율적인 거래 기간으로 인한 간섭을 방지합니다.
  4. 명확한 시각적 인터페이스를 통해 모든 기간의 추세 상태를 보여줍니다.
  5. 유연한 위치 관리 시스템은 백분율 구성을 지원합니다.

전략적 위험

  1. 변동성이 큰 시장에서는 거래 신호가 너무 많이 생성되어 거래 비용이 증가할 수 있습니다.
  2. 필터링 조건이 여러 개이면 잠재적으로 수익성이 있는 기회를 놓칠 수 있습니다.
  3. 매개변수 최적화에 따라 달라지며, 다양한 시장 환경에 따라 매개변수 조정이 필요할 수 있습니다.
  4. 계산 복잡도가 높고 프로그램 실행 효율성에 문제가 있을 수 있습니다.

전략 최적화 방향

  1. 시장 상황에 따라 Supertrend 매개변수를 동적으로 조정하는 변동성 적응 메커니즘을 도입합니다.
  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=5
strategy("Multi-Timeframe Supertrend Strategy", 
         overlay=true, 
         shorttitle="MTF Supertrend TF", 
         default_qty_type=strategy.percent_of_equity, 
         default_qty_value=100, 
         initial_capital=50000, 
         currency=currency.USD)

// === Input Parameters === //
atrPeriod = input.int(title="ATR Period", defval=10, minval=1)
factor = input.float(title="Factor", defval=3.0, step=0.1)

// === Time Filter Parameters === //
// Define the trading session using input.session
// Format: "HHMM-HHMM", e.g., "0930-1530"
sessionInput = input("0930-1530", title="Trading Session")

// Specify the timezone (e.g., "Europe/Istanbul")
// Refer to the list of supported timezones: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
timezoneInput = input.string("Europe/Istanbul", title="Timezone", tooltip="Specify a valid IANA timezone (e.g., 'Europe/Istanbul', 'America/New_York').")

// === Calculate Supertrend for Different Timeframes === //
symbol = syminfo.tickerid

// 15-Minute Supertrend
[st_15m, dir_15m] = request.security(symbol, "15", ta.supertrend(factor, atrPeriod), lookahead=barmerge.lookahead_off)

// 5-Minute Supertrend
[st_5m, dir_5m] = request.security(symbol, "5", ta.supertrend(factor, atrPeriod), lookahead=barmerge.lookahead_off)

// 2-Minute Supertrend
[st_2m, dir_2m] = request.security(symbol, "2", ta.supertrend(factor, atrPeriod), lookahead=barmerge.lookahead_off)

// === Current Timeframe Supertrend === //
[st_current, dir_current] = ta.supertrend(factor, atrPeriod)

// === Time Filter: Check if Current Bar is Within the Trading Session === //
in_session = true

// === Define Trend Directions Based on Supertrend === //
is_up_15m = close > st_15m
is_up_5m  = close > st_5m
is_up_2m  = close > st_2m
is_up_current = close > st_current

// === Buy Condition === //
buyCondition = is_up_15m and is_up_5m and is_up_2m and is_up_current and in_session and strategy.position_size == 0

// === Sell Conditions === //
// 1. Price falls below the 5-minute Supertrend during trading session
sellCondition1 = close < st_5m

// 2. End of Trading Day: Sell at the close of the trading session
is_new_day = ta.change(time("D"))
sellCondition2 = not in_session and is_new_day

// Combined Sell Condition: Only if in Position
sellSignal = (sellCondition1 and in_session) or sellCondition2
sellCondition = sellSignal and strategy.position_size > 0

// === Execute Trades === //
if (buyCondition)
    strategy.entry("Buy", strategy.long)

if (sellCondition)
    strategy.close("Buy")

// === Plot Supertrend Lines === //
// Plotting current timeframe Supertrend
plot(st_current, title="Current TF Supertrend", color=is_up_current ? color.green : color.red, linewidth=2, style=plot.style_line)

// Plotting higher timeframe Supertrend lines
plot(st_15m, title="15m Supertrend", color=is_up_15m ? color.green : color.red, linewidth=1, style=plot.style_line)
plot(st_5m, title="5m Supertrend", color=is_up_5m ? color.green : color.red, linewidth=1, style=plot.style_line)
plot(st_2m, title="2m Supertrend", color=is_up_2m ? color.green : color.red, linewidth=1, style=plot.style_line)

// === Plot Buy and Sell Signals === //
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, 
          color=color.green, style=shape.labelup, text="BUY", size=size.small)

plotshape(series=sellCondition, title="Sell Signal", location=location.abovebar, 
          color=color.red, style=shape.labeldown, text="SELL", size=size.small)

// === Optional: Background Color to Indicate Position === //
bgcolor(strategy.position_size > 0 ? color.new(color.green, 90) : na, title="In Position Background")

// === Alerts === //
// Create alerts for Buy and Sell signals
alertcondition(buyCondition, title="Buy Alert", message="Buy signal generated by MTF Supertrend Strategy with Time Filter.")
alertcondition(sellCondition, title="Sell Alert", message="Sell signal generated by MTF Supertrend Strategy with Time Filter.")