프리미엄 이중 트렌드 필터 MA 비율 전략

저자:차오장, 날짜: 2023-12-28 17:37:14
태그:

img

전반적인 설명

이 전략은 볼링거 밴드 필터와 이중 트렌드 필터 지표와 결합한 이중 이동 평균 비율 지표에 기반합니다. 트렌드를 따르는 체인 출구 메커니즘을 채택합니다. 이 전략은 이동 평균 비율 지표를 통해 중장기 트렌드 방향을 식별하는 것을 목표로합니다. 트렌드 방향이 명확하면 더 나은 입구 지점에서 시장에 진출합니다. 또한 이익을 취하고 손실을 줄이기 위해 수익을 취하고 손실을 줄이기 위해 출구 메커니즘을 설정합니다.

전략 논리

  1. 빠른 이동 평균 (10 일) 과 느린 이동 평균 (50 일) 을 계산하면 가격 이동 평균 비율이라고 불리는 비율을 얻습니다. 이 비율은 중장기 트렌드 변화를 효과적으로 식별 할 수 있습니다.
  2. 가격 이동 평균 비율을 지난 기간의 현재 비율의 상대적 강도를 나타내는 퍼센틸로 변환합니다. 이 퍼센틸은 오시레이터로 정의됩니다.
  3. 오시일레이터가 구매 진입 문턱 (10) 을 넘을 때, 긴 신호가 발동됩니다. 판매 문턱 (90) 을 넘을 때, 추세를 따르는 짧은 신호가 발동됩니다.
  4. 신호 필터링을 위해 볼링거 밴드 폭 지표와 결합합니다. BB 폭이 줄어들 때 거래하십시오.
  5. 이중 트렌드 필터 지표를 사용하십시오. 가격이 상승 트렌드 채널에있을 때만 길고 하락 트렌드에서 짧은 시간을 사용하십시오. 역 거래를 피하기 위해.
  6. 체인 출구 전략은 수익을 취하고, 손실을 멈추고, 결합 출구를 포함하여 설정됩니다. 최대 수익 출구 우선 순위를 갖춘 여러 출구 조건이 미리 설정 될 수 있습니다.

장점

  1. 이중 트렌드 필터는 역거래를 피하는 주요 트렌드를 식별하는 신뢰성을 보장합니다.
  2. MA 비율 지표는 단일 MA보다 트렌드 변화를 더 잘 감지합니다.
  3. BB 폭은 더 신뢰할 수 있는 신호를 위해 낮은 변동성을 효과적으로 찾아냅니다.
  4. 체인 출구 메커니즘은 전체 수익을 극대화합니다.

위험 과 해결책

  1. 더 많은 잘못된 신호와 변화하는 시장에서 불분명한 추세와 함께. 해결책은 더 긴 신호를 위해 BB 너비 필터와 결합하는 것입니다.
  2. MA는 트렌드 반전을 즉시 감지하지 못하는 지연 효과를 가지고 있습니다. 해결책은 MA 매개 변수를 적절히 단축하는 것입니다.
  3. 스톱 손실은 가격 격차로 즉시 타격을 받아 큰 손실을 유발할 수 있습니다. 해결책은 스톱 손실 매개 변수를 느슨하게 설정하는 것입니다.

최적화 방향

  1. 가장 좋은 조합을 찾기 위해 철저한 테스트를 통해 MA 기간, 오시레이터 임계, BB 매개 변수에서 매개 변수 최적화.
  2. 추세 반전을 판단하는 다른 지표를 포함합니다. KD, MACD 같은 것이 정확도를 향상시킵니다.
  3. 동적 매개 변수 최적화를 위한 역사적 데이터로 기계 학습 모델 훈련

요약

이 전략은 중장기 트렌드를 결정하기 위해 이중 MA 비율 지표와 BB를 통합합니다. 연쇄 수익 취득 메커니즘으로 트렌드 확인 후 최고의 시점에서 시장에 진출합니다. 매우 신뢰할 수 있고 효율적입니다. 매개 변수 최적화, 트렌드 역전 지표와 기계 학습을 추가함으로써 추가 개선이 가능합니다.


/*backtest
start: 2023-12-20 00:00:00
end: 2023-12-27 00:00:00
period: 3m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Premium MA Ratio Strategy", overlay = true)

// Input: Adjustable parameters for Premium MA Ratio
fast_length = input(10, title = "Fast MA Length")
slow_length = input(50, title = "Slow MA Length")
oscillator_threshold_buy = input(10, title = "Oscillator Buy Threshold")
oscillator_threshold_sell = input(90, title = "Oscillator Sell Threshold")

// Input: Adjustable parameters for Bollinger Bands
bb_length = input(20, title = "Bollinger Bands Length")
bb_source = input(close, title = "Bollinger Bands Source")
bb_deviation = input(2.0, title = "Bollinger Bands Deviation")
bb_width_threshold = input(30, title = "BB Width Threshold")
use_bb_filter = input(true, title = "Use BB Width Filter?")

// Input: Adjustable parameters for Trend Filter
use_trend_filter = input(true, title = "Use Trend Filter?")
trend_filter_period_1 = input(50, title = "Trend Filter Period 1")
trend_filter_period_2 = input(200, title = "Trend Filter Period 2")
use_second_trend_filter = input(true, title = "Use Second Trend Filter?")

// Input: Adjustable parameters for Exit Strategies
use_exit_strategies = input(true, title = "Use Exit Strategies?")
use_take_profit = input(true, title = "Use Take Profit?")
take_profit_ticks = input(150, title = "Take Profit in Ticks")
use_stop_loss = input(true, title = "Use Stop Loss?")
stop_loss_ticks = input(100, title = "Stop Loss in Ticks")
use_combined_exit = input(true, title = "Use Combined Exit Strategy?")
combined_exit_ticks = input(50, title = "Combined Exit Ticks")

// Input: Adjustable parameters for Time Filter
use_time_filter = input(false, title = "Use Time Filter?")
start_hour = input(8, title = "Start Hour")
end_hour = input(16, title = "End Hour")

// Calculate moving averages
fast_ma = sma(close, fast_length)
slow_ma = sma(close, slow_length)

// Calculate the premium price moving average ratio
premium_ratio = fast_ma / slow_ma * 100

// Calculate the percentile rank of the premium ratio
percentile_rank(src, length) =>
    rank = 0.0
    for i = 1 to length
        if src > src[i]
            rank := rank + 1.0
    percentile = rank / length * 100

// Calculate the percentile rank for the premium ratio using slow_length periods
premium_ratio_percentile = percentile_rank(premium_ratio, slow_length)

// Calculate the oscillator based on the percentile rank
oscillator = premium_ratio_percentile

// Dynamic coloring for the oscillator line
oscillator_color = oscillator > 50 ? color.green : color.red

// Plot the oscillator on a separate subplot as a line
hline(50, "Midline", color = color.gray)
plot(oscillator, title = "Oscillator", color = oscillator_color, linewidth = 2)

// Highlight the overbought and oversold areas
bgcolor(oscillator > oscillator_threshold_sell ? color.red : na, transp = 80)
bgcolor(oscillator < oscillator_threshold_buy ? color.green : na, transp = 80)

// Plot horizontal lines for threshold levels
hline(oscillator_threshold_buy, "Buy Threshold", color = color.green)
hline(oscillator_threshold_sell, "Sell Threshold", color = color.red)

// Calculate Bollinger Bands width
bb_upper = sma(bb_source, bb_length) + bb_deviation * stdev(bb_source, bb_length)
bb_lower = sma(bb_source, bb_length) - bb_deviation * stdev(bb_source, bb_length)
bb_width = bb_upper - bb_lower

// Calculate the percentile rank of Bollinger Bands width
bb_width_percentile = percentile_rank(bb_width, bb_length)

// Plot the Bollinger Bands width percentile line
plot(bb_width_percentile, title = "BB Width Percentile", color = color.blue, linewidth = 2)

// Calculate the trend filters
trend_filter_1 = sma(close, trend_filter_period_1)
trend_filter_2 = sma(close, trend_filter_period_2)

// Strategy logic
longCondition = crossover(premium_ratio_percentile, oscillator_threshold_buy)
shortCondition = crossunder(premium_ratio_percentile, oscillator_threshold_sell)

// Apply Bollinger Bands width filter if enabled
if (use_bb_filter)
    longCondition := longCondition and bb_width_percentile < bb_width_threshold
    shortCondition := shortCondition and bb_width_percentile < bb_width_threshold

// Apply trend filters if enabled
if (use_trend_filter)
    longCondition := longCondition and (close > trend_filter_1)
    shortCondition := shortCondition and (close < trend_filter_1)

// Apply second trend filter if enabled
if (use_trend_filter and use_second_trend_filter)
    longCondition := longCondition and (close > trend_filter_2)
    shortCondition := shortCondition and (close < trend_filter_2)

// Apply time filter if enabled
if (use_time_filter)
    longCondition := longCondition and (hour >= start_hour and hour <= end_hour)
    shortCondition := shortCondition and (hour >= start_hour and hour <= end_hour)

// Generate trading signals with exit strategies
if (use_exit_strategies)
    strategy.entry("Buy", strategy.long, when = longCondition)
    strategy.entry("Sell", strategy.short, when = shortCondition)
    
    // Define unique exit names for each order
    buy_take_profit_exit = "Buy Take Profit"
    buy_stop_loss_exit = "Buy Stop Loss"
    sell_take_profit_exit = "Sell Take Profit"
    sell_stop_loss_exit = "Sell Stop Loss"
    combined_exit = "Combined Exit"
    
    // Exit conditions for take profit
    if (use_take_profit)
        strategy.exit(buy_take_profit_exit, from_entry = "Buy", profit = take_profit_ticks)
        strategy.exit(sell_take_profit_exit, from_entry = "Sell", profit = take_profit_ticks)
    
    // Exit conditions for stop loss
    if (use_stop_loss)
        strategy.exit(buy_stop_loss_exit, from_entry = "Buy", loss = stop_loss_ticks)
        strategy.exit(sell_stop_loss_exit, from_entry = "Sell", loss = stop_loss_ticks)
    
    // Combined exit strategy
    if (use_combined_exit)
        strategy.exit(combined_exit, from_entry = "Buy", loss = combined_exit_ticks, profit = combined_exit_ticks)



더 많은