다중 동적 지표 조합 전략

ATR BB ST MA VWMA
생성 날짜: 2025-04-01 10:12:19 마지막으로 수정됨: 2025-04-01 10:12:19
복사: 4 클릭수: 294
avatar of ianzeng123 ianzeng123
2
집중하다
319
수행원

다중 동적 지표 조합 전략 다중 동적 지표 조합 전략

개요

이 글은 부린 밴드와 슈퍼 트렌드 지표를 결합한 복합 거래 전략에 대해 소개한다. 이 전략은 여러 가지 기술적 분석 도구를 통합하여 보다 정확한 시장 진입 및 출구 신호를 제공하면서 거래 위험을 줄이는 것을 목표로 한다.

전략 원칙

이 전략의 핵심은 두 가지 주요 부분으로 구성됩니다: 볼링거 밴드 (Bollinger Bands) 및 슈퍼 트렌드 (SuperTrend) 지표.

  1. 브린의 계산 부분:
  • 설정 가능한 이동 평균 ((MA) 를 사용하여 기준선을 계산
  • 표준차의 배수에 따라 상하 궤도를 생성
  • 여러 가지 이동 평균 유형을 지원합니다: 간단한 이동 평균 (SMA), 지수 이동 평균 (EMA), 평평한 이동 평균 (SMMA), 가중 이동 평균 (WMA) 및 거래량 가중 이동 평균 (VWMA)
  1. 슈퍼 트렌드 (SuperTrend)
  • 평균 실제 변동 범위 (ATR) 를 사용하여 스톱 로스를 계산합니다.
  • 동적 판단 시장 추세 방향
  • 트렌드 변화에 따라 구매/판매 신호를 생성합니다.

전략적 이점

  1. 다중 지표 조합: 브린 밴드와 슈퍼 트렌드를 결합하여 신호 정확도를 향상시킵니다.
  2. 유연한 구성: 이동 평균 유형, 매개 변수 및 계산 방법을 사용자 정의할 수 있습니다.
  3. 동적 중지: ATR 기반의 중지 메커니즘은 위험을 효과적으로 제어합니다.
  4. 시각적 강화: 트렌드 상태 채우기 및 신호 태그를 제공합니다
  5. 리스크 관리: 퍼센티지 관리 및 피라미드 거래 제한을 설정

전략적 위험

  1. 매개 변수 감수성: 다른 시장 환경에서 매개 변수가 자주 조정될 수 있습니다.
  2. 역추적의 한계: 과거 데이터의 성능은 미래 시장의 성능을 나타내지 않습니다.
  3. 빈번한 포지션 전환이 거래 비용을 증가시킬 수 있는 다중 전환 위험
  4. 지표 지연성: 기술 지표에 약간의 신호 지연이 있다.

전략 최적화 방향

  1. 기계 학습 알고리즘의 동적 최적화 매개 변수를 도입
  2. 추가적인 필터링 조건을 추가합니다.
  3. 다중 시간 프레임 검증 메커니즘 개발
  4. 리스크 관리 모듈을 최적화하여 보다 정교한 포지션 제어 전략을 도입

요약하다

이것은 여러 역동적인 지표들을 결합한 거래 전략이며, 브린 밴드와 슈퍼 트렌드의 조합을 통해 비교적 포괄적인 거래 신호 시스템을 제공합니다. 전략의 핵심은 신호 정확성과 위험 관리를 균형 잡는 데 있습니다. 그러나 다양한 시장 환경에 따라 지속적으로 최적화 및 조정해야합니다.

전략 소스 코드
/*backtest
start: 2024-04-01 00:00:00
end: 2025-03-31 00:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

//@version=6
strategy("Combined BB & New SuperTrend Strategy", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0)

//============================
// Bollinger Bands Parameters
//============================
lengthBB   = input.int(20, minval=1, title="BB Length")
maType     = input.string("SMA", "BB Basis MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
srcBB      = input(close, title="BB Source")
multBB     = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev Multiplier")
offsetBB   = input.int(0, title="BB Offset", minval=-500, maxval=500)

// Moving average function based on chosen type
ma(source, length, _type) =>
    switch _type
        "SMA"         => ta.sma(source, length)
        "EMA"         => ta.ema(source, length)
        "SMMA (RMA)"  => ta.rma(source, length)
        "WMA"         => ta.wma(source, length)
        "VWMA"        => ta.vwma(source, length)

// Bollinger Bands calculations
basis   = ma(srcBB, lengthBB, maType)
dev     = multBB * ta.stdev(srcBB, lengthBB)
upperBB = basis + dev
lowerBB = basis - dev

// Plot Bollinger Bands
plot(basis, title="BB Basis", color=color.blue, offset=offsetBB)
p1 = plot(upperBB, title="BB Upper", color=color.red, offset=offsetBB)
p2 = plot(lowerBB, title="BB Lower", color=color.green, offset=offsetBB)
fill(p1, p2, title="BB Fill", color=color.new(color.blue, 90))

//============================
// New SuperTrend Parameters & Calculations
// (Based on the new script you provided)
//============================
st_length         = input.int(title="ATR Period", defval=22)
st_mult           = input.float(title="ATR Multiplier", step=0.1, defval=3)
st_src            = input.source(title="SuperTrend Source", defval=hl2)
st_wicks          = input.bool(title="Take Wicks into Account?", defval=true)
st_showLabels     = input.bool(title="Show Buy/Sell Labels?", defval=true)
st_highlightState = input.bool(title="Highlight State?", defval=true)

// Calculate ATR component for SuperTrend
st_atr = st_mult * ta.atr(st_length)

// Price selection based on wicks option
st_highPrice = st_wicks ? high : close
st_lowPrice  = st_wicks ? low  : close
st_doji4price = (open == close and open == low and open == high)

// Calculate SuperTrend stop levels
st_longStop = st_src - st_atr
st_longStopPrev = nz(st_longStop[1], st_longStop)
if st_longStop > 0
    if st_doji4price
        st_longStop := st_longStopPrev
    else
        st_longStop := (st_lowPrice[1] > st_longStopPrev ? math.max(st_longStop, st_longStopPrev) : st_longStop)
else
    st_longStop := st_longStopPrev

st_shortStop = st_src + st_atr
st_shortStopPrev = nz(st_shortStop[1], st_shortStop)
if st_shortStop > 0
    if st_doji4price
        st_shortStop := st_shortStopPrev
    else
        st_shortStop := (st_highPrice[1] < st_shortStopPrev ? math.min(st_shortStop, st_shortStopPrev) : st_shortStop)
else
    st_shortStop := st_shortStopPrev

// Determine trend direction: 1 for bullish, -1 for bearish
var int st_dir = 1
st_dir := st_dir == -1 and st_highPrice > st_shortStopPrev ? 1 : st_dir == 1 and st_lowPrice < st_longStopPrev ? -1 : st_dir

// Define colors for SuperTrend
st_longColor  = color.green
st_shortColor = color.red

// Plot SuperTrend stops
st_longStopPlot  = plot(st_dir == 1 ? st_longStop : na, title="Long Stop", style=plot.style_line, linewidth=2, color=st_longColor)
st_shortStopPlot = plot(st_dir == -1 ? st_shortStop : na, title="Short Stop", style=plot.style_line, linewidth=2, color=st_shortColor)

// Generate SuperTrend signals based on direction change
st_buySignal  = st_dir == 1 and st_dir[1] == -1
st_sellSignal = st_dir == -1 and st_dir[1] == 1

// Optionally plot labels for buy/sell signals
if st_buySignal and st_showLabels
    label.new(bar_index, st_longStop, "Buy", style=label.style_label_up, color=st_longColor, textcolor=color.white, size=size.tiny)
if st_sellSignal and st_showLabels
    label.new(bar_index, st_shortStop, "Sell", style=label.style_label_down, color=st_shortColor, textcolor=color.white, size=size.tiny)

// Fill the state area (optional visual enhancement)
st_midPricePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=1, display=display.none)
st_longFillColor  = st_highlightState ? (st_dir == 1 ? st_longColor : na) : na
st_shortFillColor = st_highlightState ? (st_dir == -1 ? st_shortColor : na) : na
fill(st_midPricePlot, st_longStopPlot, title="Long State Filling", color=st_longFillColor)
fill(st_midPricePlot, st_shortStopPlot, title="Short State Filling", color=st_shortFillColor)

//============================
// Trading Logic
//============================

// When a bullish reversal occurs, close any short position before entering long.
if st_buySignal
    strategy.close("Short")
    strategy.entry("Long", strategy.long)

// When a bearish reversal occurs, close any long position before entering short.
if st_sellSignal
    strategy.close("Long")
    strategy.entry("Short", strategy.short)

// Exit conditions using Bollinger Bands:
// - For a long position: exit if price reaches (or exceeds) the upper Bollinger Band.
// - For a short position: exit if price reaches (or falls below) the lower Bollinger Band.
if strategy.position_size > 0 and close >= upperBB
    strategy.close("Long", comment="Exit Long via BB Upper")
if strategy.position_size < 0 and close <= lowerBB
    strategy.close("Short", comment="Exit Short via BB Lower")