게으른 곰 압축 모멘텀 전략

저자:차오장, 날짜: 2024-02-02 17:42:58
태그:

img

전반적인 설명

게으른 곰 압축 모멘텀 전략 (Lazy Bear Squeeze Momentum strategy) 은 볼링거 밴드, 켈트너 채널 및 모멘텀 인디케이터를 결합한 양적 거래 전략이다. 현재 시장이 압축 중인지 여부를 결정하기 위해 볼링거 밴드 및 켈트너 채널을 활용하고, 모멘텀 인디케이터를 사용하여 거래 신호를 생성합니다.

이 전략의 주요 장점은 트렌드 움직임의 시작을 자동으로 식별하고 모멘텀 지표로 진입 시기를 결정 할 수 있다는 것입니다. 그러나 다른 제품 간 최적화를 통해 해결해야 할 특정 위험이 있습니다.

전략 논리

게으른 곰 압축 모멘텀 전략은 다음 세 가지 지표에 기초하여 판단합니다.

  1. 볼링거 밴드: 중간 밴드, 상부 밴드 및 하부 밴드를 포함합니다.
  2. 켈트너 채널: 중선, 상선, 하선
  3. 모멘텀 지표: 현재 가격 빼기 n 일 전 가격

볼링거 상단역이 켈트너 상단선 아래에 있고, 볼링거 하단역이 켈트너 하단선 위에 있을 때, 우리는 시장이 압축 상태에 있음을 결정합니다. 이것은 일반적으로 트렌드 움직임이 시작될 것이라는 것을 의미합니다.

진입 시기를 파악하기 위해, 우리는 가격 변화 속도를 측정하기 위해 모멘텀 지표를 사용합니다. 모멘텀이 이동 평균보다 높을 때 구매 신호가 생성되며, 모멘텀이 이동 평균보다 낮을 때 판매 신호가 생성됩니다.

이점 분석

게으른 곰 압축 모멘텀 전략의 주요 장점:

  1. 새로운 트렌드에 대한 초기 항목을 자동으로 식별
  2. 표시기 조합은 잘못된 신호를 방지합니다.
  3. 트렌드와 평균 반전을 모두 포착합니다.
  4. 최적화를 위한 사용자 정의 가능한 매개 변수
  5. 다양한 제품에서 견고합니다.

위험 분석

또한 게으른 곰 압축 모멘텀 전략에는 특정 위험이 있습니다:

  1. 볼링거 앤드 켈트너의 잘못된 신호의 확률
  2. 추진력 불안정성, 최고의 엔트리가 없어
  3. 최적화 없이 낮은 성능
  4. 제품 선택에 대한 높은 상관관계

위험을 완화하기 위해 권장 사항은: 볼링거 & 켈트너의 길이를 최적화하고, 스톱 로스를 조정하고, 유동 상품을 선택하고, 신호를 다른 지표로 확인하는 것입니다.

최적화 방향

성능 향상을 위한 주요 방향:

  1. 제품 및 시간 프레임에 걸쳐 매개 변수 조합 테스트
  2. 볼린거 밴드 및 켈트너 채널의 길이를 최적화합니다.
  3. 동력 표시기의 길이를 최적화
  4. 롱과 쇼트에서 다른 스톱 로스/프로프트 취득
  5. 신호 검증을 위한 추가 지표

엄격한 테스트와 최적화를 통해 전략의 우수성과 수익성이 크게 향상될 수 있습니다.

결론

게으른 곰 압축 모멘텀 전략은 멀티 지표 접근 방식을 통해 강력한 신호 생성을 가지고 있으며 새로운 트렌드 시작을 효과적으로 식별 할 수 있습니다. 그러나 또한 거래 도구 전반에 최적화를 필요로하는 위험을 안고 있습니다. 지속적인 테스트와 향상으로 강력한 알고리즘 거래 시스템이 될 수 있습니다.


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

//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mtahreemalam original strategy by LazyBear

strategy(title = 'SQM Strategy, TP & SL',
         shorttitle = 'Squeeze.M Strat',
         overlay = true,
         pyramiding = 0,
         default_qty_type = strategy.percent_of_equity,
         default_qty_value = 100,
         initial_capital = 1000,
         commission_type=strategy.commission.percent, 
         commission_value=0.0,
         process_orders_on_close=true,
         use_bar_magnifier=true)
//Strategy logic
strategy_logic = input.string("Cross above 0", "Strategy Logic", options = ["LazyBear", "Cross above 0"])

// Date Range
testPeriodSwitch = input(false, "Custom Backtesting Date Range",group="Backtesting Date Range")
i_startTime = input(defval = timestamp("01 Jan 2022 00:01 +0000"), title = "Backtesting Start Time",group="Backtesting Date Range")
i_endTime = input(defval = timestamp("31 Dec 2022 23:59 +0000"), title = "Backtesting End Time",group="Backtesting Date Range")
timeCond = true
isPeriod = testPeriodSwitch == true ? timeCond : true

//// Stoploss and Take Profit Parameters
// Enable Long Strategy
enable_long_strategy = input.bool(true, title='Enable Long Strategy', group='SL/TP For Long Strategy', inline='1')
long_stoploss_value = input.float(defval=5, title='Stoploss %', minval=0.1, group='SL/TP For Long Strategy', inline='2')
long_stoploss_percentage = close * (long_stoploss_value / 100) / syminfo.mintick
long_takeprofit_value = input.float(defval=5, title='Take Profit %', minval=0.1, group='SL/TP For Long Strategy', inline='2')
long_takeprofit_percentage = close * (long_takeprofit_value / 100) / syminfo.mintick

// Enable Short Strategy
enable_short_strategy = input.bool(true, title='Enable Short Strategy', group='SL/TP For Short Strategy', inline='3')
short_stoploss_value = input.float(defval=5, title='Stoploss %', minval=0.1, group='SL/TP For Short Strategy', inline='4')
short_stoploss_percentage = close * (short_stoploss_value / 100) / syminfo.mintick
short_takeprofit_value = input.float(defval=5, title='Take Profit %', minval=0.1, group='SL/TP For Short Strategy', inline='4')
short_takeprofit_percentage = close * (short_takeprofit_value / 100) / syminfo.mintick

//// Inputs
//SQUEEZE MOMENTUM STRATEGY
length = input(20, title='BB Length', group = "Squeeze Momentum Settings")
mult = input(2.0, title='BB MultFactor', group = "Squeeze Momentum Settings")
source = close
lengthKC = input(20, title='KC Length', group = "Squeeze Momentum Settings")
multKC = input(1.5, title='KC MultFactor', group = "Squeeze Momentum Settings")
useTrueRange = input(true, title='Use TrueRange (KC)', group = "Squeeze Momentum Settings")
signalPeriod=input(5, title="Signal Length", group = "Squeeze Momentum Settings")
show_labels_sqm = input(title='Show Buy/Sell SQM Labels', defval=true, group = "Squeeze Momentum Settings")
h0 = hline(0)

// Defining MA
ma = ta.sma(source, length)

// Calculate BB
basis = ma
dev = mult * ta.stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev

// Calculate KC
range_1 = useTrueRange ? ta.tr : high - low
rangema = ta.sma(range_1, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC


// SqzON | SqzOFF | noSqz
sqzOn = lowerBB > lowerKC and upperBB < upperKC
sqzOff = lowerBB < lowerKC and upperBB > upperKC
noSqz = sqzOn == false and sqzOff == false

// Momentum
val = ta.linreg(source - math.avg(math.avg(ta.highest(high, lengthKC), ta.lowest(low, lengthKC)), ta.sma(close, lengthKC)), lengthKC, 0)

red_line = ta.sma(val,signalPeriod)
blue_line = val

// lqm = if val > 0
//         if val > nz(val[1])
        // long_sqm_custom
        // if val < nz(val[1])
        // short_sqm_custom
// Plots
//plot(val, style = plot.style_line, title = "blue line", color= color.blue, linewidth=2)
//plot(ta.sma(val,SignalPeriod), style = plot.style_line, title = "red line",color = color.red, linewidth=2)

//plot(val, color=blue, linewidth=2)
//plot(0, color=color.gray, style=plot.style_cross, linewidth=2)
//plot(red_line, color=red, linewidth=2)

//LOGIC
//momentum filter
//filterMom = useMomAverage ? math.abs(val) > MomentumMin / 100000 ? true : false : true
//}

////SQM Long Short Conditions
//Lazy Bear Buy Sell Condition
// long_sqm_lazy = (blue_line>red_line)
// short_sqm_lazy = (blue_line<red_line)

long_sqm_lazy = ta.crossover(blue_line,red_line)
short_sqm_lazy = ta.crossunder(blue_line,red_line)


//Custom Buy Sell Condition
dir_sqm = val < 0 ? -1 : 1
long_sqm_custom = dir_sqm == 1 //and dir_sqm[1] == -1
short_sqm_custom = dir_sqm == -1 //and dir_sqm[1] == 1

long_sqm = strategy_logic == "LazyBear" ? long_sqm_lazy : long_sqm_custom 
short_sqm = strategy_logic == "LazyBear" ? short_sqm_lazy : short_sqm_custom 


// Plot Stoploss & Take Profit Levels
long_stoploss_price = strategy.position_avg_price * (1 - long_stoploss_value / 100)
long_takeprofit_price = strategy.position_avg_price * (1 + long_takeprofit_value / 100)
short_stoploss_price = strategy.position_avg_price * (1 + short_stoploss_value / 100)
short_takeprofit_price = strategy.position_avg_price * (1 - short_takeprofit_value / 100)
plot(enable_long_strategy and not enable_short_strategy ? long_stoploss_percentage : na, color=color.red, style=plot.style_linebr, linewidth=2, title='Long SL Level')
plot(enable_long_strategy and not enable_short_strategy ? long_takeprofit_percentage : na, color=color.green, style=plot.style_linebr, linewidth=2, title='Long TP Level')
plot(enable_short_strategy and not enable_long_strategy ? short_stoploss_price : na, color=color.red, style=plot.style_linebr, linewidth=2, title='Short SL Level')
plot(enable_short_strategy and not enable_long_strategy ? short_takeprofit_price : na, color=color.green, style=plot.style_linebr, linewidth=2, title='Short TP Level')


// Long Strategy
if long_sqm and enable_long_strategy == true
    strategy.entry('Long', strategy.long)
    strategy.exit('Long  SL/TP', from_entry='Long', loss=long_stoploss_percentage, profit=long_takeprofit_percentage)
    strategy.close('Long', comment = "L. CL")

// Short Strategy
if short_sqm and enable_short_strategy == true 
    strategy.entry('Short', strategy.short)
    strategy.exit('Short SL/TP', from_entry='Short', loss=short_stoploss_percentage, profit=short_takeprofit_percentage)
    strategy.close('Short', comment = "S.Cl")

plot_sqm_long = long_sqm and not long_sqm[1]
plot_sqm_short = short_sqm and not short_sqm[1]

plotshape(plot_sqm_long and show_labels_sqm, title='Buy', style=shape.labelup, location=location.belowbar, size=size.normal, text='Buy', textcolor=color.new(color.white, 0), color=color.new(color.green, 0))
plotshape(plot_sqm_short and show_labels_sqm, title='Sell', style=shape.labeldown, location=location.abovebar, size=size.normal, text='Sell', textcolor=color.new(color.white, 0), color=color.new(color.red, 0))

// Date Range EXIT
if (not isPeriod) 
    strategy.cancel_all()
    strategy.close_all()


더 많은