듀얼 트렌드 필터링 체인 이동 평균 비율 전략


생성 날짜: 2023-12-28 17:37:14 마지막으로 수정됨: 2023-12-28 17:37:14
복사: 1 클릭수: 623
avatar of ChaoZhang ChaoZhang
1
집중하다
1623
수행원

듀얼 트렌드 필터링 체인 이동 평균 비율 전략

개요

이 전략은 쌍방 이동 평균 비율 지표에 기초하여, 부린이 가지고 있는 필터와 쌍방 트렌드 필터 지표를 결합하여, 체인식 탈퇴 메커니즘을 사용하는 트렌드 추적 전략이다. 이 전략은 이동 평균 비율 지표를 사용하여 중장선 트렌드 방향을 식별하고, 트렌드 방향이 명확할 때 더 좋은 입문 장소를 선택하고, 스톱, 스톱 손실 탈퇴 메커니즘을 설정하여 수익을 잠금하고, 손실을 줄이는 것이다.

전략 원칙

  1. 빠른 이동 평균 ((10일선) 과 느린 이동 평균 ((50일선) 을 계산하고, 그 비율을 계산하여 가격 이동 평균 비율이라고 한다. 이 비율은 가격의 긴 선의 경향의 변화를 효과적으로 식별할 수 있다.
  2. 가격 이동 평균 비율을 현재 비율이 지난 기간에 비해 상대적으로 강하다는 비율로 변환한다. 이 비율은 오징어로 정의된다.
  3. 진동기는 상단에서 설정된 구매한값 ((10) 을 넘으면 구매한 신호를 발생시키고, 하단에서 판매한값 ((90) 을 넘으면 판매한 신호를 발생시키며, 트렌드 따를 수 있다.
  4. 부린 대역폭 지표와 결합하여 거래 신호를 필터링하고, 부린 대역이 좁아질 때 동작한다.
  5. 이중 트렌드 필터링 지표를 사용하여, 가격이 상승 트렌드 채널에 있을 때만 구매 신호를 생성하고, 가격이 하락 채널에 있을 때만 판매 신호를 생성하여 역동 조작을 피한다.
  6. 체인형 탈퇴 메커니즘을 설정하여, 스톱, 스톱 손실 및 포트폴리오 탈퇴를 포함하여, 여러 탈퇴 조건을 미리 설정할 수 있으며, 가장 수익성이 높은 탈퇴 조건을 우선적으로 선택할 수 있다.

전략적 이점

  1. 이중 트렌드 필터링 메커니즘, 주 트렌드 방향을 안정적으로 판단하고 역경 조작을 피한다.
  2. 이동 평균 비율 지표는 단일 이동 평균보다 트렌드 변화를 더 효과적으로 판단한다.
  3. 브린 대역폭 지표는 거래 신호가 더 신뢰할 수 있는 시장의 낮은 변동 기간을 효과적으로 파악할 수 있다.
  4. 연쇄적 탈퇴는 수익을 안정화하고 전체 수익을 극대화합니다.

위험과 해결책

  1. 진동상태에서 명백한 추세가 없을 때, 더 많은 잘못된 신호와 반전이 나타난다. 해결 방법은 부린 대역폭을 필터링하고, 축소할 때 동작하는 것이다.
  2. 명백한 트렌드 반전이 있을 때, 이동 평균은 지연성을 생성하고, 반전 신호를 처음으로 판단할 수 없다. 해결책은 이동 평균 주기 변수를 적절히 줄이는 것이다.
  3. 실황상 공중뛰기 공백이 발생했을 때, 정지점은 순간적으로 타격되어 큰 손실을 초래할 수 있다. 해결 방법은 정지점을 적절히 풀어주는 파라미트이다.

전략 최적화 방향

  1. 변수 최적화. 이동 평균 주기, 진동기 매매점, 브린 대역 변수, 트렌드 필터 변수 등에 대한 간략한 테스트를 통해 최적의 변수 조합을 찾을 수 있다.
  2. 다른 지표들을 통합한다. KD 지표, MACD 지표 등과 같은 다른 추세 반전을 판단하는 지표들을 포함하는 것을 고려할 수 있다. 전략의 정확성을 향상시킨다.
  3. 기계 학습 은 역사 데이터를 수집하고, 기계 학습 알고리즘을 사용하여 모델을 훈련하고, 동적으로 여러 가지 매개 변수를 최적화하여 매개 변수를 자율적으로 조정할 수 있다.

요약하다

이 전략은 쌍동이 이동 평균 비율 지표와 브린 벨트 지표를 사용하여 중장선 트렌드 방향을 판단하고, 트렌드를 확인한 후 최적의 입문 포인트를 찾으며, 체인형 탈퇴 메커니즘을 설정하여 수익을 고정합니다. 신뢰성이 높고, 효과는 분명합니다. 이 전략은 변수 최적화, 다른 보조 판단 지표 및 기계 학습을 추가하여 수익률을 향상시키고 향상시킬 수 있습니다.

전략 소스 코드
/*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)