단계적 BB KC 트렌드 전략

저자:차오장, 날짜: 2024-01-26 15:10:41
태그:

img

전반적인 설명

이 전략은 시장 트렌드를 식별하기 위해 볼링거 밴드 및 켈트너 채널 신호의 조합을 사용합니다. 볼링거 밴드는 가격 변동성 범위를 기반으로 채널을 정의하는 기술 분석 도구입니다. 켈트너 채널 신호는 지지 또는 저항 수준을 결정하기 위해 가격 변동성과 트렌드를 결합합니다. 이 전략은 볼링거 밴드와 켈트너 채널 사이에 황금 십자가가 발생하는지 판단하여 장기 및 단기 기회를 찾도록 두 지표의 장점을 활용합니다. 또한 신호의 유효성을 확인하기 위해 거래 부피를 통합하여 트렌드의 시작을 효과적으로 식별하고 유효하지 않은 신호의 필터링을 극대화 할 수 있습니다.

전략 원칙

  1. 중간, 상부, 하부 볼링거 대역을 20개 기간에 걸쳐 계산합니다. 대역 폭은 2개의 표준편차로 정의됩니다.
  2. 중간, 상부, 하부 켈트너 채널을 20개의 기간에 걸쳐 계산합니다. 채널 너비는 실제 범위의 2.2배로 정의됩니다.
  3. 켈트너 채널 상선은 볼링거 밴드 상선을 넘어서면, 부피가 10주기 이동 평균보다 커지면, 긴 거래가 됩니다.
  4. 켈트너 채널 하위 선이 볼링거 밴드 하위 선 아래를 넘어서서 볼륨이 10 기간 이동 평균보다 커지면, 단위로 가십시오.
  5. 입점 후 20 바가 지나면 출구 신호가 발사되지 않으면 모든 위치를 닫습니다.
  6. 긴 거래에 1.5%의 스톱 로스를 설정하고 짧은 거래에 -1.5%의 스톱 로스를 설정합니다. 긴 거래에 2%의 트레일링 스톱과 짧은 거래에 -2%의 트레일링 스톱을 설정합니다.

이 전략은 주로 변동성 범위와 추진력을 판단하기 위해 볼링거 밴드에 의존합니다. 켈트너 채널은 유사한 특성이지만 다른 매개 변수로 인해 확인 도구로 사용됩니다. 이 두 지표를 함께 사용하면 신호 정확성이 향상됩니다. 거래 부피를 통합하는 것은 유효하지 않은 신호를 필터링하는 데도 도움이됩니다.

강도 분석

  1. 신호의 정확성을 향상시키기 위해 볼링거 대역과 켈트너 채널의 복합 장점을 활용합니다.
  2. 거래량에 따른 필터링은 빈번한 라인 터치로 인한 유효하지 않은 신호를 줄여줍니다.
  3. 프로그램된 스톱 로스 및 트레일링 스톱 메커니즘을 통해 효과적인 리스크 제어
  4. 빠른 출구와 손실 제한은 유효하지 않은 신호에 따라 강제 수익을 취하는 것입니다.

위험 분석

  1. 볼링거 대역과 켈트너 채널은 모두 이동 평균과 변동성을 기반으로 합니다. 그들은 시장의 범위에서 잘못된 신호를 생성할 수 있습니다.
  2. 복합 메커니즘이 없다는 것은 여러 번의 정지 종료가 너무 큰 손실로 이어질 수 있다는 것을 의미합니다.
  3. 반전 신호는 자주 발생합니다. 매개 변수 조정으로 인해 트렌드 기회가 놓칠 수 있습니다.

스톱 로스 범위를 넓히거나 MACD와 같은 확인 지표를 추가하면 잘못된 신호의 위험을 줄일 수 있습니다.

최적화 방향

  1. 길이, 표준편차 배수 등 전략 수익에 대한 테스트 매개 변수 영향
  2. 신호 확인을 위한 다른 지표, 예를 들어 KDJ, MACD를 추가합니다.
  3. 자동화된 매개 변수 최적화를 위해 머신러닝을 사용하세요.

요약

이 전략은 거래량에 의해 검증되는 트렌드를 식별하기 위해 볼링거 밴드와 켈트너 채널을 결합합니다. 매개 변수 최적화 및 지표 추가와 같은 추가 개선은 더 많은 시장 체제에 대해 강화 할 것입니다. 이해하기 쉽고 사용자 정의 가능한 거래 전략으로 강력한 타당성을 가지고 있습니다.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jensenvilhelm

//@version=5
strategy("BB and KC Strategy", overlay=true)

// Define the input parameters for the strategy, these can be changed by the user to adjust the strategy
kcLength = input.int(20, "KC Length", minval=1) // Length for Keltner Channel calculation
kcStdDev = input.float(2.2, "KC StdDev") // Standard Deviation for Keltner Channel calculation
bbLength = input.int(20, "BB Length", minval=1) // Length for Bollinger Bands calculation
bbStdDev = input.float(2, "BB StdDev") // Standard Deviation for Bollinger Bands calculation
volumeLength = input.int(10, "Volume MA Length", minval=1) // Length for moving average of volume calculation
stopLossPercent = input.float(1.5, "Stop Loss (%)") // Percent of price for Stop loss 
trailStopPercent = input.float(2, "Trail Stop (%)") // Percent of price for Trailing Stop
barsInTrade = input.int(20, "Bars in trade before exit", minval = 1) // Minimum number of bars in trade before considering exit

// Calculate Bollinger Bands and Keltner Channel
[bb_middle, bb_upper, bb_lower] = ta.bb(close, bbLength, bbStdDev) // Bollinger Bands calculation
[kc_middle, kc_upper, kc_lower] = ta.kc(close, kcLength, kcStdDev) // Keltner Channel calculation

// Calculate moving average of volume
vol_ma = ta.sma(volume, volumeLength) // Moving average of volume calculation

// Plotting Bollinger Bands and Keltner Channels on the chart
plot(bb_upper, color=color.red) // Bollinger Bands upper line
plot(bb_middle, color=color.blue) // Bollinger Bands middle line
plot(bb_lower, color=color.red) // Bollinger Bands lower line
plot(kc_upper, color=color.rgb(105, 255, 82)) // Keltner Channel upper line
plot(kc_middle, color=color.blue) // Keltner Channel middle line
plot(kc_lower, color=color.rgb(105, 255, 82)) // Keltner Channel lower line

// Define entry conditions: long position if upper KC line crosses above upper BB line and volume is above MA of volume
// and short position if lower KC line crosses below lower BB line and volume is above MA of volume
longCond = ta.crossover(kc_upper, bb_upper) and volume > vol_ma // Entry condition for long position
shortCond = ta.crossunder(kc_lower, bb_lower) and volume > vol_ma // Entry condition for short position

// Define variables to store entry price and bar counter at entry point
var float entry_price = na // variable to store entry price
var int bar_counter = na // variable to store bar counter at entry point

// Check entry conditions and if met, open long or short position
if (longCond)
    strategy.entry("Buy", strategy.long) // Open long position
    entry_price := close // Store entry price
    bar_counter := 1 // Start bar counter
if (shortCond)
    strategy.entry("Sell", strategy.short) // Open short position
    entry_price := close // Store entry price
    bar_counter := 1 // Start bar counter

// If in a position and bar counter is not na, increment bar counter
if (strategy.position_size != 0 and na(bar_counter) == false)
    bar_counter := bar_counter + 1 // Increment bar counter

// Define exit conditions: close position if been in trade for more than specified bars
// or if price drops by more than specified percent for long or rises by more than specified percent for short
if (bar_counter > barsInTrade) // Only consider exit after minimum bars in trade
    if (bar_counter >= barsInTrade)
        strategy.close_all() // Close all positions
    // Stop loss and trailing stop
    if (strategy.position_size > 0)
        strategy.exit("Sell", "Buy", stop=entry_price * (1 - stopLossPercent/100), trail_points=entry_price * trailStopPercent/100) // Set stop loss and trailing stop for long position
    else if (strategy.position_size < 0)
        strategy.exit("Buy", "Sell", stop=entry_price * (1 + stopLossPercent/100), trail_points=entry_price * trailStopPercent/100) // Set stop loss and trailing stop for short position


더 많은