LazyBear

Trading Strategy based on BB/KC squeeze

**** [Edit: New version (v02) posted, see the comments section for the code *****

Simple strategy. You only consider taking a squeeze play when both the upper and lower Bollinger Bands go inside the Keltner Channel. When the Bollinger Bands (BOTH lines) start to come out of the Keltner Channel, the squeeze has been released and a move is about to take place.

I have added more support indicators -- I highlight the bullish / bearish KC breaches (using GREEN/RED crosses) and a SAR to see where price action is trending.

Appreciate any feedback. Enjoy!

Color codes for v02:
----------------------------
When both the upper and lower Bollinger Bands go inside the Keltner Channel, the squeeze is on and is highlighted in RED.
When the Bollinger Bands (BOTH lines) start to come out of the Keltner Channel, the squeeze has been released and is highlighted in GREEN.
When one of the Bollinger Bands is out of Keltner Channel, no highlighting is done (this means, the background color shows up, so don't get confused if you have RED/GREEN in your chart's bground :))

Color codes for v01:
----------------------------
When both the upper and lower Bollinger Bands go inside the Keltner Channel, the squeeze is on and is highlighted in YELLOW.
When the Bollinger Bands (BOTH lines) start to come out of the Keltner Channel, the squeeze has been released and is highlighted in BLUE.

List of my free indicators: bit.ly/1LQaPK8
List of my indicators at Appstore: blog.tradingview.com/?p=970
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?
//
// @author LazyBear
// @credits http://www.hiltinvestmentfund.com/html/squeeze.html
// Trading strategy based on Bollinger Bands & Keltner Channel. Added SAR / Highlights to make it really easy ;)
// v01 - initial release
//
study(shorttitle = "TS 1 [LB]", title="Trading strategy [BB / KC] [LazyBear]", overlay=true)

length = input(20, minval=1, title="Length"), mult = input(1.0, minval=0.001, maxval=50, title="MultFactor")
// showBarColor = input(true, title="Highlight Bear/Bull points (KC)", type=bool)
showBarColor = false
useTrueRange = input(false, title="Use TrueRange (KC)", type=bool)
// Note that "highlightStrategy" takes precedence over showBarColor. 
highlightStrategy = input(true, title="Highlight strategy points", type=bool)

startSAR = input(0.02, title="Start (SAR)")
incrementSAR = input(0.02, title="Increment (SAR)")
maximumSAR = input(0.2, title="Maximum (SAR)")

// Calculate BB
source = close
basis = sma(source, length)
dev = mult * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
plot(basis, color=red, linewidth=2)
p1 = plot(upperBB, color=red,  linewidth=2)
p2 = plot(lowerBB, color=red, linewidth=2)
fill(p1, p2, color = red)

// Calculate KC
ma = ema(source, length)
range = useTrueRange ? tr : high - low
rangema = ema(range, length)
upper = ma + rangema * mult
lower = ma - rangema * mult
c = lime
u = plot(upper, color=c, title="Upper")
plot(ma, color=c, title="Basis")
l = plot(lower, color=c, title="Lower")
fill(u, l, color=green, transp=80)

offset = 2
bearish = low < lower
bear_point = bearish ? (low-offset) : na
bear_color = bearish ? red : na
bullish = high > upper
bull_point = bullish ? (high+offset) : na
bull_color = bullish ? green : na

bar_color = bearish ? bear_color : (bullish ? bull_color : na)
plot(bear_point, color = bear_color, style=cross, linewidth=2)
plot(bull_point, color = bull_color, style=cross, linewidth=2)

bgcolor((showBarColor and not highlightStrategy) ? bar_color : na)

strat_sqz_color = ((upperBB < upper) and (lowerBB > lower)) ? yellow : blue
bgcolor(highlightStrategy ? strat_sqz_color : na)

// SAR
outSAR = sar(startSAR, incrementSAR, maximumSAR)
plot(outSAR, style=cross, color=blue)