다기간 시장 피로 분석 전략 및 위험 관리 시스템

ATR RRR SL TP DD
생성 날짜: 2025-02-10 14:27:15 마지막으로 수정됨: 2025-02-10 14:27:15
복사: 1 클릭수: 370
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

다기간 시장 피로 분석 전략 및 위험 관리 시스템

개요

이 전략은 시장 피로 분석을 기반으로 한 다층 거래 시스템으로, 가격 동력의 심층적 분석을 통해 시장이 전환 할 수있는 중요한 순간을 식별합니다. 이 전략은 자금 관리, 스톱 로즈 최적화 및 철회 제어와 같은 여러 차원을 포함하는 동적인 위험 관리 메커니즘을 결합하여 완전한 거래 의사 결정 프레임 워크를 형성합니다.

전략 원칙

전략의 핵심은 가격의 연속적인 움직임을 모니터링하여 시장 피로도를 판단하는 것입니다.

  1. 4 K 선의 종전 가격과 현재 종전 가격을 비교하여 트렌드 방향을 결정합니다.
  2. 세 가지 다른 강도 (9/12/14) 의 신호 트리거 포인트를 설정합니다.
  3. 가격이 한 방향으로 계속 움직일 때, 시스템은 신호를 축적합니다.
  4. 기본 신호 강도 임계값에 도달하면, 시스템은 적절한 수준의 거래 신호를 제공합니다.
  5. ATR 기반의 다이내믹 스톱 로즈 메커니즘과 리스크 리터너스 비율을 통합한 포지션 관리 시스템

전략적 이점

  1. 다단계 신호 시스템은 거래 기회를 식별하는 다양한 수준을 제공합니다.
  2. 자금 관리 및 위험 제어 장치를 통해 자금 안전을 보호하십시오.
  3. ATR의 동적 상쇄는 시장의 변동에 더 잘 적응할 수 있습니다.
  4. 이윤을 더 잘 고정할 수 있는 추적 스톱 손실 메커니즘을 도입했습니다.
  5. 최대 회수 보호 장치로 과도한 손실을 방지합니다.
  6. 시스템에는 좋은 확장성과 변수 최적화 공간이 있습니다.

전략적 위험

  1. 시장이 흔들리는 상황에서 잘못된 신호가 발생할 수 있습니다.
  2. 고정된 신호값은 모든 시장 환경에 적합하지 않을 수 있습니다.
  3. 급격한 역전 시에는 더 큰 손실이 발생할 수 있습니다.
  4. 더 많은 변수 최적화 작업이 필요합니다.
  5. 자금 관리 시스템은 어떤 경우에는 수익을 제한할 수 있습니다.

전략 최적화 방향

  1. 시장의 변동률 필터링 메커니즘을 도입하여 다양한 변동 환경에서 신호 값을 조정합니다.
  2. 볼륨 분석의 차원을 확대하고 신호 신뢰성을 향상시킵니다.
  3. 자율적인 변수 최적화 시스템 개발
  4. 더 많은 시장 환경 분석 지표를 추가합니다.
  5. 자금 관리 시스템을 최적화하여 더 유연하게 만듭니다.

요약하다

이 전략은 다층의 피로 분석과 완벽한 위험 관리 시스템을 통해 거래자에게 체계화된 거래 프레임 워크를 제공합니다. 일부 최적화가 필요한 부분이 있지만 전체적인 설계 아이디어는 온전하고 실제 응용 가치가 있습니다. 현장에서 보수적인 자금 관리 전략을 채택하고 지속적으로 변수 최적화 및 시스템 개선을 수행하는 것이 좋습니다.

전략 소스 코드
/*backtest
start: 2024-02-10 00:00:00
end: 2025-02-08 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=6
strategy(title="Improved Exhaustion Signal with Risk Management and Drawdown Control", shorttitle="Exhaustion Signal", overlay=true)

// ———————————————— INPUT SETTINGS ————————————————
showLevel1 = input.bool(true, 'Show Level 1 Signals')
showLevel2 = input.bool(true, 'Show Level 2 Signals')
showLevel3 = input.bool(true, 'Show Level 3 Signals')

// Thresholds for signal strength levels
level1 = 9
level2 = 12
level3 = 14

// Risk management inputs
riskPercentage = input.float(1.0, title="Risk Percentage per Trade", minval=0.1, maxval=5.0)  // Risk per trade in percentage
riskRewardRatio = input.float(2.0, title="Risk-to-Reward Ratio", minval=1.0, maxval=5.0)  // Reward-to-risk ratio
trailingStop = input.bool(true, title="Enable Trailing Stop")  // Enable/Disable trailing stop
trailingStopDistance = input.int(50, title="Trailing Stop Distance (in points)", minval=1)  // Distance for trailing stop

// Drawdown protection settings
maxDrawdown = input.float(10.0, title="Max Drawdown Percentage", minval=0.1, maxval=50.0)  // Max allowable drawdown before stopping trading

// ———————————————— GLOBAL VARIABLES ————————————————
var int cycle = 0
var int bullishSignals = 0
var int bearishSignals = 0
var float equityHigh = na  // Initialize as undefined

// Track equity drawdown
if (na(equityHigh) or strategy.equity > equityHigh)
    equityHigh := strategy.equity

drawdownPercent = 100 * (equityHigh - strategy.equity) / equityHigh

// Stop trading if drawdown exceeds the limit
if drawdownPercent >= maxDrawdown
    strategy.close_all()

// ———————————————— FUNCTION: RESET & IMMEDIATE RECHECK USING AN ARRAY RETURN ————————————————
f_resetAndRecheck(_bullish, _bearish, _cycle, _close, _close4) =>
    newBullish = _bullish
    newBearish = _bearish
    newCycle = _cycle

    // Reset cycle if necessary based on price action
    newBullish := 0
    newBearish := 0
    newCycle := 0

    if _close < _close4
        newBullish := 1
        newCycle := newBullish
    else if _close > _close4
        newBearish := 1
        newCycle := newBearish

    resultArray = array.new_int(3, 0)
    array.set(resultArray, 0, newBullish)
    array.set(resultArray, 1, newBearish)
    array.set(resultArray, 2, newCycle)

    resultArray

// ———————————————— EXHAUSTION LOGIC ————————————————
if cycle < 9
    // Bullish cycle: close < close[4]
    if close < close[4]
        bullishSignals += 1
        bearishSignals := 0
        cycle := bullishSignals
    // Bearish cycle: close > close[4]
    else if close > close[4]
        bearishSignals += 1
        bullishSignals := 0
        cycle := bearishSignals
    else
        newVals = f_resetAndRecheck(bullishSignals, bearishSignals, cycle, close, close[4])
        bullishSignals := array.get(newVals, 0)
        bearishSignals := array.get(newVals, 1)
        cycle := array.get(newVals, 2)
else
    // ——— BULLISH checks ———
    if bullishSignals > 0
        if bullishSignals < (level3 - 1)
            if close < close[3]
                bullishSignals += 1
                bearishSignals := 0
                cycle := bullishSignals
            else
                newVals = f_resetAndRecheck(bullishSignals, bearishSignals, cycle, close, close[4])
                bullishSignals := array.get(newVals, 0)
                bearishSignals := array.get(newVals, 1)
                cycle := array.get(newVals, 2)
        else if bullishSignals == (level3 - 1)
            if close < close[2]
                bullishSignals := level3
                cycle := bullishSignals
            else
                newVals = f_resetAndRecheck(bullishSignals, bearishSignals, cycle, close, close[4])
                bullishSignals := array.get(newVals, 0)
                bearishSignals := array.get(newVals, 1)
                cycle := array.get(newVals, 2)
        else
            newVals = f_resetAndRecheck(bullishSignals, bearishSignals, cycle, close, close[4])
            bullishSignals := array.get(newVals, 0)
            bearishSignals := array.get(newVals, 1)
            cycle := array.get(newVals, 2)
    // ——— BEARISH checks ———
    else if bearishSignals > 0
        if bearishSignals < (level3 - 1)
            if close > close[3]
                bearishSignals += 1
                bullishSignals := 0
                cycle := bearishSignals
            else
                newVals = f_resetAndRecheck(bullishSignals, bearishSignals, cycle, close, close[4])
                bullishSignals := array.get(newVals, 0)
                bearishSignals := array.get(newVals, 1)
                cycle := array.get(newVals, 2)
        else if bearishSignals == (level3 - 1)
            if close > close[2]
                bearishSignals := level3
                cycle := bearishSignals
            else
                newVals = f_resetAndRecheck(bullishSignals, bearishSignals, cycle, close, close[4])
                bullishSignals := array.get(newVals, 0)
                bearishSignals := array.get(newVals, 1)
                cycle := array.get(newVals, 2)
        else
            newVals = f_resetAndRecheck(bullishSignals, bearishSignals, cycle, close, close[4])
            bullishSignals := array.get(newVals, 0)
            bearishSignals := array.get(newVals, 1)
            cycle := array.get(newVals, 2)
    else
        newVals = f_resetAndRecheck(bullishSignals, bearishSignals, cycle, close, close[4])
        bullishSignals := array.get(newVals, 0)
        bearishSignals := array.get(newVals, 1)
        cycle := array.get(newVals, 2)

// ———————————————— SIGNAL FLAGS ————————————————
bullishLevel1 = showLevel1 and (bullishSignals == level1)
bearishLevel1 = showLevel1 and (bearishSignals == level1)

bullishLevel2 = showLevel2 and (bullishSignals == level2)
bearishLevel2 = showLevel2 and (bearishSignals == level2)

bullishLevel3 = showLevel3 and (bullishSignals == level3)
bearishLevel3 = showLevel3 and (bearishSignals == level3)

// ———————————————— PLOT SIGNALS ————————————————
plotshape(bullishLevel1, style=shape.diamond, color=color.new(#30ff85, 0), textcolor=color.white, size=size.tiny, location=location.belowbar, title="Level 1 Bullish Signal")
plotshape(bearishLevel1, style=shape.diamond, color=color.new(#ff1200, 0), textcolor=color.white, size=size.tiny, location=location.abovebar, title="Level 1 Bearish Signal")

plotshape(bullishLevel2, style=shape.xcross, color=color.new(#30ff85, 0), textcolor=color.white, size=size.tiny, location=location.belowbar, title="Level 2 Bullish Signal")
plotshape(bearishLevel2, style=shape.xcross, color=color.new(#ff1200, 0), textcolor=color.white, size=size.tiny, location=location.abovebar, title="Level 2 Bearish Signal")

plotshape(bullishLevel3, style=shape.flag, color=color.new(#30ff85, 0), textcolor=color.white, size=size.tiny, location=location.belowbar, title="Level 3 Bullish Signal")
plotshape(bearishLevel3, style=shape.flag, color=color.new(#ff1200, 0), textcolor=color.white, size=size.tiny, location=location.abovebar, title="Level 3 Bearish Signal")

// ———————————————— RESET AFTER LEVEL 3 ————————————————
if bullishSignals == level3 or bearishSignals == level3
    bullishSignals := 0
    bearishSignals := 0
    cycle := 0

// ———————————————— BACKTEST LOGIC ————————————————
// Set up basic long and short entry conditions based on signal levels
longCondition = bullishLevel1 or bullishLevel2 or bullishLevel3
shortCondition = bearishLevel1 or bearishLevel2 or bearishLevel3

// Calculate position size based on risk percentage
equity = strategy.equity
riskAmount = equity * riskPercentage / 100
atr = ta.atr(14)
stopLossLevel = atr * 1.5  // Using ATR for dynamic stop-loss
positionSize = riskAmount / stopLossLevel

// Initialize strategy logic
if longCondition
    strategy.entry("Long", strategy.long, qty=positionSize)

if shortCondition
    strategy.entry("Short", strategy.short, qty=positionSize)

// ———————————————— CONCRETE STOP LOSS AND TAKE PROFIT ————————————————
stopLoss = stopLossLevel
takeProfit = stopLoss * riskRewardRatio

// Apply stop loss and take profit to the strategy based on concrete price levels
strategy.exit("Exit Long", from_entry="Long", stop=close - stopLoss, limit=close + takeProfit)
strategy.exit("Exit Short", from_entry="Short", stop=close + stopLoss, limit=close - takeProfit)

// ———————————————— TRAILING STOP ————————————————
if trailingStop
    strategy.exit("Exit Long Trailing", from_entry="Long", trail_price=close - trailingStopDistance, trail_offset=trailingStopDistance)
    strategy.exit("Exit Short Trailing", from_entry="Short", trail_price=close + trailingStopDistance, trail_offset=trailingStopDistance)