동적 손절매 및 목표 이익에 기반한 EMA 다중 비용 가중 평균 비용 전략


생성 날짜: 2024-01-19 15:16:53 마지막으로 수정됨: 2024-01-19 15:16:53
복사: 2 클릭수: 778
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

동적 손절매 및 목표 이익에 기반한 EMA 다중 비용 가중 평균 비용 전략

개요

이 전략은 동적 다중 지수 이동 평균을 시장 진입 신호로 사용하고, 스톱 손실과 목표 수익을 추적하는 메커니즘과 결합하여 위험과 수익을 관리합니다. 이 전략은 EMA의 부드러운 특성을 최대한 활용하여 트렌드를 식별하고, DCA의 여러 투입을 통해 비용을 제어합니다. 또한 동적 스톱 손실과 목표 수익을 통합하여 전체 전략을 더 지능화하고 자동화합니다.

전략 원칙

지표 계산

  • EMA5, EMA10, EMA20, EMA50, EMA100, EMA200 지수 이동 평균
  • ATR 평균 실제 변동폭

시내 진입 신호

가격이 설정된 EMA 주기에 가까워지거나 통과했을 때 출시 신호가 발생하며, EMA 주기는 사용자 정의 할 수 있으며, 전형적으로 5, 10, 20, 50, 100, 200 주기를 선택한다. 이 전략은 가격이 EMA 상하 1% 범위에서 출시 조건으로 채택한다.

위험 관리

여러 위험 관리 메커니즘을 통합합니다.

  1. ATR 중지: ATR이 설정된 임계치를 초과할 때 청산 중지
  2. 최대 출시 수 제한: 과잉 투입을 피하십시오
  3. 동적 추적 스톱: 가격의 실시간 변동에 따라 트레일링 스톱

수익 메커니즘

목표 수익 수준을 설정하고 목표 가격을 초과하면 종료

전략적 강점 분석

  1. EMA를 사용하여 트렌드를 인식하고, 단기 변동에 대한 필터링을 수행합니다.
  2. DCA 비용 분산, 낮은 가격으로 구매하는 것을 피합니다.
  3. 다중 EMA 포트폴리오, 상장 성공률 향상
  4. 동적 중지 손실 REAL-TIME 제어 손실
  5. 수익을 내기 위한 목표가 명확하고, 많은 수익을 낭비하지 않는다.

위험과 개선

  1. EMA 요소 선택은 최적화가 필요하며, 시장에 따라 다른 주기의 조합 효과에 큰 차이가 있습니다.
  2. 너무 많은 DCA 사용이 과도한 사용으로 이어질 수 있습니다.
  3. 정지폭 설정은 재측정 최적화가 필요합니다.

전략적 최적화

  1. 고급 EMA 시스템을 사용하여 트렌드를 식별합니다.
  2. 다 변수 최적화 최적 DCA 횟수 및 중지 범위
  3. 가격 변화를 예측하는 기계 학습 모형에 추가
  4. 통합 자금 관리 모듈 전체 투입 제어

요약하다

이 전략은 EMA 트렌드 식별, DCA 비용 제어, 동적 추적 스톱 로즈, 목표 수익 철수와 같은 여러 메커니즘을 통합합니다. 변수 조정 및 위험 제어 측면에서 많은 최적화 공간이 있습니다. 전체적으로 이 전략은 강한 적응력과 확장성을 가지고 있으며 투자자에게 안정적인 초과 수익을 가져올 수 있습니다.

전략 소스 코드
/*backtest
start: 2023-01-12 00:00:00
end: 2024-01-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("EMA DCA Strategy with Trailing Stop and Profit Target", overlay=true )

// Define the investment amount for when the condition is met
investment_per_condition = 6

// Define the EMAs
ema5 = ema(close, 5)
ema10 = ema(close, 10)
ema20 = ema(close, 20)
ema50 = ema(close, 50)
ema100 = ema(close, 100)
ema200 = ema(close, 200)

// Define ATR sell threshold
atr_sell_threshold = input(title="ATR Sell Threshold", type=input.integer, defval=10, minval=1)

// Helper function to find if the price is within 1% of the EMA
isWithin1Percent(price, ema) =>
    ema_min = ema * 0.99
    ema_max = ema * 1.01
    price >= ema_min and price <= ema_max

// Control the number of buys
var int buy_count = 0
buy_limit = input(title="Buy Limit", type=input.integer, defval=3000)

// Calculate trailing stop and profit target levels
trail_percent = input(title="Trailing Stop Percentage", type=input.integer, defval=1, minval=0, maxval=10)
profit_target_percent = input(title="Profit Target Percentage", type=input.integer, defval=3, minval=1, maxval=10)

// Determine if the conditions are met and execute the strategy
checkConditionAndBuy(emaValue, emaName) =>
    var int local_buy_count = 0 // Create a local mutable variable
    if isWithin1Percent(close, emaValue) and local_buy_count < buy_limit
        strategy.entry("Buy at " + emaName, strategy.long, qty=investment_per_condition / close, alert_message ="Buy condition met for " + emaName)
        local_buy_count := local_buy_count + 1
        // alert("Buy Condition", "Buy condition met for ", freq_once_per_bar_close)
        
    local_buy_count // Return the updated local_buy_count

// Add ATR sell condition
atr_condition = atr(20) > atr_sell_threshold
if atr_condition
    strategy.close_all()
    buy_count := 0 // Reset the global buy_count when selling

// Strategy execution
buy_count := checkConditionAndBuy(ema5, "EMA5")
buy_count := checkConditionAndBuy(ema10, "EMA10")
buy_count := checkConditionAndBuy(ema20, "EMA20")
buy_count := checkConditionAndBuy(ema50, "EMA50")
buy_count := checkConditionAndBuy(ema100, "EMA100")
buy_count := checkConditionAndBuy(ema200, "EMA200")

// Calculate trailing stop level
trail_offset = close * trail_percent / 100
trail_level = close - trail_offset

// Set profit target level
profit_target_level = close * (1 + profit_target_percent / 100)

// Exit strategy: Trailing Stop and Profit Target
strategy.exit("TrailingStop", from_entry="Buy at EMA", trail_offset=trail_offset, trail_price=trail_level)
strategy.exit("ProfitTarget", from_entry="Buy at EMA",  when=close >= profit_target_level)

// Plot EMAs
plot(ema5, title="EMA 5", color=color.red)
plot(ema10, title="EMA 10", color=color.orange)
plot(ema20, title="EMA 20", color=color.yellow)
plot(ema50, title="EMA 50", color=color.green)
plot(ema100, title="EMA 100", color=color.blue)
plot(ema200, title="EMA 200", color=color.purple)