다단계 변동성 적응형 동적 슈퍼트렌드 전략

ATR SMA STD TP
생성 날짜: 2024-11-29 16:57:19 마지막으로 수정됨: 2024-11-29 16:57:19
복사: 0 클릭수: 439
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

다단계 변동성 적응형 동적 슈퍼트렌드 전략

개요

다단계 변동률 자율 적응 동적 초트렌드 전략은 베가스 채널과 슈퍼트렌드 지표를 결합한 혁신적인 거래 시스템이다. 이 전략의 특징은 시장의 변동성에 동적으로 적응할 수 있는 능력과 리스크 수익률을 최적화하기 위해 다단계 스톱 메커니즘을 사용하는 데 있다. 전략은 베가스 채널의 변동성 분석과 슈퍼트렌드의 트렌드 추적 기능을 결합하여 시장 조건이 변할 때 자동으로 매개 변수를 조정하여 더 정확한 거래 신호를 제공합니다.

전략 원칙

전략은 세 가지 핵심 구성 요소에 기반하여 작동합니다: 베가스 통로 계산, 트렌드 탐지 및 다단계 정지 메커니즘. 베가스 통로는 가격 변동 범위를 정의하기 위해 간단한 이동 평균 ((SMA) 및 표준 격차 ((STD) 를 사용하며, SuperTrend 지표는 조정된 ATR 값에 따라 트렌드 방향을 결정합니다. 시장 추세가 변경되면 시스템은 거래 신호를 생성합니다. 다단계 정지 메커니즘은 다른 가격 수준에서 대량으로 탈퇴를 허용합니다. 이 방법은 수익을 잠금화 할 수 있지만 일부 포지션은 잠재적인 수익을 계속 얻을 수 있습니다.

전략적 이점

  1. 동적 적응성: 변동률 조정 인자를 통해 전략은 다양한 시장 조건에 자동으로 적응할 수 있다.
  2. 리스크 관리: 다단계 차단 메커니즘은 체계화된 수익결과를 제공합니다.
  3. 사용자 정의: 다양한 거래 스타일을 충족시키기 위해 여러 가지 변수 설정 옵션을 제공합니다.
  4. 전체 시장 커버리지: 다방면 양방향 거래를 지원한다.
  5. 시각적 피드백: 분석과 의사결정을 위한 명확한 그래픽 인터페이스를 제공합니다.

전략적 위험

  1. 변수 민감성: 다른 변수 조합으로 인해 전략 성능에 큰 차이가 발생할 수 있습니다.
  2. 뒤처짐: 이동 평균에 기반한 지표가 다소 뒤쳐져 있다.
  3. 가짜 돌파의 위험: 가로판 시장에서 잘못된 신호가 발생할 수 있다.
  4. 정지 설정의 균형: 조기 정지하면 큰 추세를 놓칠 수 있고, 너무 늦게 정지하면 이미 이윤을 잃게 될 수 있습니다.

전략 최적화 방향

  1. 시장 환경 필터를 도입하여 다른 시장 조건에 따라 전략 매개 변수를 조정합니다.
  2. 트래픽 분석을 늘리고 신호 신뢰도를 높여라.
  3. 시장의 변동에 따라 조절할 수 있는 자동 조절 장치를 개발한다.
  4. 다른 기술 지표를 통합하여 신호 확인을 제공합니다.
  5. 동적 포지션 관리를 구현하고, 시장 위험에 따라 거래 규모를 조정한다.

요약하다

다단계 변동율 자율 적응 동적 초상향 전략은 여러 기술 지표와 혁신적인 정지 메커니즘을 결합하여 거래자에게 포괄적 인 거래 시스템을 제공하는 첨단 양적 거래 방법을 나타냅니다. 그 동적 적응력과 위험 관리 기능은 다양한 시장 환경에서 작동하는 데 특히 적합하며 확장성과 최적화 공간을 제공합니다. 지속적인 개선과 최적화를 통해 이 전략은 미래에 더 안정적인 거래 성능을 제공 할 수 있습니다.

전략 소스 코드
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Multi-Step Vegas SuperTrend - strategy [presentTrading]", shorttitle="Multi-Step Vegas SuperTrend - strategy [presentTrading]", overlay=true, precision=3, commission_value=0.1, commission_type=strategy.commission.percent, slippage=1, currency=currency.USD)

// Input settings allow the user to customize the strategy's parameters.
tradeDirectionChoice = input.string(title="Trade Direction", defval="Both", options=["Long", "Short", "Both"]) // Option to select the trading direction
atrPeriod = input(10, "ATR Period for SuperTrend") // Length of the ATR for volatility measurement
vegasWindow = input(100, "Vegas Window Length") // Length of the moving average for the Vegas Channel
superTrendMultiplier = input(5, "SuperTrend Multiplier Base") // Base multiplier for the SuperTrend calculation
volatilityAdjustment = input.float(5, "Volatility Adjustment Factor") // Factor to adjust the SuperTrend sensitivity to the Vegas Channel width

// User inputs for take profit settings
useTakeProfit = input.bool(true, title="Use Take Profit", group="Take Profit Settings")
takeProfitPercent1 = input.float(3.0, title="Take Profit % Step 1", group="Take Profit Settings")
takeProfitPercent2 = input.float(6.0, title="Take Profit % Step 2", group="Take Profit Settings")
takeProfitPercent3 = input.float(12.0, title="Take Profit % Step 3", group="Take Profit Settings")
takeProfitPercent4 = input.float(21.0, title="Take Profit % Step 4", group="Take Profit Settings")

takeProfitAmount1 = input.float(25, title="Take Profit Amount % Step 1", group="Take Profit Settings")
takeProfitAmount2 = input.float(20, title="Take Profit Amount % Step 2", group="Take Profit Settings")
takeProfitAmount3 = input.float(10, title="Take Profit Amount % Step 3", group="Take Profit Settings")
takeProfitAmount4 = input.float(15, title="Take Profit Amount % Step 4", group="Take Profit Settings")

numberOfSteps = input.int(4, title="Number of Take Profit Steps", minval=1, maxval=4, group="Take Profit Settings")

// Calculate the Vegas Channel using a simple moving average and standard deviation.
vegasMovingAverage = ta.sma(close, vegasWindow)
vegasChannelStdDev = ta.stdev(close, vegasWindow)
vegasChannelUpper = vegasMovingAverage + vegasChannelStdDev
vegasChannelLower = vegasMovingAverage - vegasChannelStdDev

// Adjust the SuperTrend multiplier based on the width of the Vegas Channel.
channelVolatilityWidth = vegasChannelUpper - vegasChannelLower
adjustedMultiplier = superTrendMultiplier + volatilityAdjustment * (channelVolatilityWidth / vegasMovingAverage)

// Calculate the SuperTrend indicator values.
averageTrueRange = ta.atr(atrPeriod)
superTrendUpper = hlc3 - (adjustedMultiplier * averageTrueRange)
superTrendLower = hlc3 + (adjustedMultiplier * averageTrueRange)
var float superTrendPrevUpper = na
var float superTrendPrevLower = na
var int marketTrend = 1

// Update SuperTrend values and determine the current trend direction.
superTrendPrevUpper := nz(superTrendPrevUpper[1], superTrendUpper)
superTrendPrevLower := nz(superTrendPrevLower[1], superTrendLower)
marketTrend := close > superTrendPrevLower ? 1 : close < superTrendPrevUpper ? -1 : nz(marketTrend[1], 1)
superTrendUpper := marketTrend == 1 ? math.max(superTrendUpper, superTrendPrevUpper) : superTrendUpper
superTrendLower := marketTrend == -1 ? math.min(superTrendLower, superTrendPrevLower) : superTrendLower
superTrendPrevUpper := superTrendUpper
superTrendPrevLower := superTrendLower

// Enhanced Visualization
// Plot the SuperTrend and Vegas Channel for visual analysis.
plot(marketTrend == 1 ? superTrendUpper : na, "SuperTrend Upper", color=color.green, linewidth=2)
plot(marketTrend == -1 ? superTrendLower : na, "SuperTrend Lower", color=color.red, linewidth=2)
plot(vegasChannelUpper, "Vegas Upper", color=color.purple, linewidth=1)
plot(vegasChannelLower, "Vegas Lower", color=color.purple, linewidth=1)

// Apply a color to the price bars based on the current market trend.
barcolor(marketTrend == 1 ? color.green : marketTrend == -1 ? color.red : na)

// Detect trend direction changes and plot entry/exit signals.
trendShiftToBullish = marketTrend == 1 and marketTrend[1] == -1
trendShiftToBearish = marketTrend == -1 and marketTrend[1] == 1

plotshape(series=trendShiftToBullish, title="Enter Long", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(series=trendShiftToBearish, title="Enter Short", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")

// Define conditions for entering long or short positions, and execute trades based on these conditions.
enterLongCondition = marketTrend == 1
enterShortCondition = marketTrend == -1

// Check trade direction choice before executing trade entries.
if enterLongCondition and (tradeDirectionChoice == "Long" or tradeDirectionChoice == "Both")
    strategy.entry("Long Position", strategy.long)

if enterShortCondition and (tradeDirectionChoice == "Short" or tradeDirectionChoice == "Both")
    strategy.entry("Short Position", strategy.short)

// Close all positions when the market trend changes.
if marketTrend != marketTrend[1]
    strategy.close_all()

// Multi-Stage Take Profit Logic
if (strategy.position_size > 0)
    entryPrice = strategy.opentrades.entry_price(strategy.opentrades - 1)
    if numberOfSteps >= 1
        strategy.exit("Take Profit 1", from_entry="Long Position", qty_percent=takeProfitAmount1, limit=entryPrice * (1 + takeProfitPercent1 / 100))
    if numberOfSteps >= 2
        strategy.exit("Take Profit 2", from_entry="Long Position", qty_percent=takeProfitAmount2, limit=entryPrice * (1 + takeProfitPercent2 / 100))
    if numberOfSteps >= 3
        strategy.exit("Take Profit 3", from_entry="Long Position", qty_percent=takeProfitAmount3, limit=entryPrice * (1 + takeProfitPercent3 / 100))
    if numberOfSteps >= 4
        strategy.exit("Take Profit 4", from_entry="Long Position", qty_percent=takeProfitAmount4, limit=entryPrice * (1 + takeProfitPercent4 / 100))

if (strategy.position_size < 0)
    entryPrice = strategy.opentrades.entry_price(strategy.opentrades - 1)
    if numberOfSteps >= 1
        strategy.exit("Take Profit 1", from_entry="Short Position", qty_percent=takeProfitAmount1, limit=entryPrice * (1 - takeProfitPercent1 / 100))
    if numberOfSteps >= 2
        strategy.exit("Take Profit 2", from_entry="Short Position", qty_percent=takeProfitAmount2, limit=entryPrice * (1 - takeProfitPercent2 / 100))
    if numberOfSteps >= 3
        strategy.exit("Take Profit 3", from_entry="Short Position", qty_percent=takeProfitAmount3, limit=entryPrice * (1 - takeProfitPercent3 / 100))
    if numberOfSteps >= 4
        strategy.exit("Take Profit 4", from_entry="Short Position", qty_percent=takeProfitAmount4, limit=entryPrice * (1 - takeProfitPercent4 / 100))