저자:차오장, 날짜: 2024-01-19 15:16:53
태그:

img

전반적인 설명

이 전략은 리스크 관리를 위해 후속 스톱 로스 및 이익 목표 메커니즘과 결합한 입력 신호로 동적 복수의 EMA를 활용합니다. 멀티 DCA 엔트리를 통해 트렌드를 식별하고 비용을 제어하기 위해 EMA의 부드러운 성격을 활용합니다. 또한 적응 스톱 로스 및 이익 취득 기능의 통합은 자동화 프로세스를 향상시킵니다.

전략 논리

지표

  • EMA5, EMA10, EMA20, EMA50, EMA100, EMA200
  • 평균 실제 범위 (ATR)

입력 신호

선택된 EMA 기간의 범위를 넘거나 이동할 때 긴 엔트리를 유발합니다. 전형적인 EMA에는 5, 10, 20, 50, 100, 200 기간이 포함됩니다. 이 전략은 엔트리 기준으로 EMA의 1% 범위를 사용합니다.

위험 관리

  1. ATR Stop Loss: ATR가 임금을 초과하면 모든 포지션을 닫습니다.
  2. 입력 주파수 제한: 입력 최대 수를 제어
  3. 마이너스 스톱 로스 (Trailing Stop Loss): 가격 움직임에 따른 동적 스톱 로스

이익 취득

장점

  1. 다중 DCA 항목을 통한 비용 평균화
  2. EMA 콤보를 이용한 강화된 입력 신호

위험 과 개선

  1. 다른 시장에 대한 최적화를 필요로 하는 EMA 조정
  2. 과도한 DCA 적립은 너무 많은 자본을 차지할 수 있습니다.
  3. 스톱 로스 비율은 백테스팅이 필요합니다.

강화 전략

  1. 추세를 더 잘 식별하기 위해 고급 EMA 시스템을 활용
  2. DCA 주파수 및 중지 손실 비율의 다변수 최적화
  3. 전체 자본 활용을 관리하기 위해 포지션 사이징 모듈을 통합합니다.

결론

이 전략은 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)


더 많은