kingthies

Logarithmic Bollinger Bands

kingthies 업데이트됨   
Logarithmic Bollinger Bands
Published by Eric Thies on January 14, 2022

Summary
In this script I have taken the standard Bollinger band pinescript and made efforts to eliminate the behavior experienced in periods of high volatility in which we see the bands disappear completely off the chart by adding exponential plotting and logarithmic sourcing to the tool.

This tool will also show periods of Bearish and Bullish Expansion for users to see when volatility is running high in the market.

More On Bollinger Bands
​Bollinger Bands consist of a center line representing the moving average of a security’s price over a certain period, and two additional parallel lines (called the upper and lower trading bands) one of which is just the moving average plus k-times the standard deviation over the selected time frame, and the other being the moving average minus k-times the standard deviation over that same timeframe. This technique has been developed in the 1980’s by John Bollinger, who lately registered the terms “Bollinger Bands” as a U.S. trademark in 2011. Technical analysts typically use 20 periods and k = 2 as default settings to build Bollinger Bands, while they can choose a simple or exponential moving average. Bollinger Bands provide a relative definition of high and low prices of a security. When the security is trading within the upper band, the price is considered high, while it is considered low when the security is trading within the lower band.

​There is no general consensus on the use of Bollinger Bands among traders. Some traders see a buy signal when the price hits the lower Bollinger Band and close their position when the price hits the moving average. Some others buy when the price crosses over the upper band and sell when the price crosses below the lower band. We can see here two opposing interpretations based on different rationales, depending whether we are in a reversal or continuation pattern. Another interesting feature of the Bollinger Bands is that they give an indication of the volatility levels; a widening gap between the upper and lower bands indicates an increasing volatility, while a narrowing band indicates a decreasing volatility. Moreover, when the bands have an almost flat slope (parallel to the x-axis) the price will generally oscillate between the bands as if trading through a channel.


 //  © 2022 KINGTHIES THIS SOURCE CODE IS SUBJECT TO TERMS OF MOZILLA PUBLIC LICENSE 2.0 (MOZILLA.ORG/MPL/2.0)
//@version=5
//## !<----------------  © KINGTHIES --------------------->
indicator('Logarithmic Bollinger Bands (kingthies)',shorttitle='LogBands_KT',overlay=true)

// { BBANDS
src = math.log(input(close,title="Source"))
lenX = input(20,title='lenX')
highlights = input(false,title="Highlight Bear and Bull Expansions?")
mult = 2
bbandBasis = ta.sma(src,lenX)
dev = 2 * ta.stdev(src, 20)
upperBB = bbandBasis + dev
lowerBB = bbandBasis - dev
bbw = (upperBB-lowerBB)/bbandBasis
bbr = (src - lowerBB)/(upperBB - lowerBB)
// }

// { BBAND EXPANSIONS
bullExp= ta.rising(upperBB,1) and ta.falling(lowerBB,1) and ta.rising(bbandBasis,1) and ta.rising(bbw,1) and ta.rising(bbr,1) 
bearExp= ta.rising(upperBB,1) and ta.falling(lowerBB,1) and ta.falling(bbandBasis,1) and ta.rising(bbw,1) and ta.falling(bbr,1) 
// } 

// { COLORS 
greenBG = color.rgb(9,121,105,75), redBG = color.rgb(136,8,8,75)
bullCol = highlights and bullExp ? greenBG : na, bearCol = highlights and bearExp ? redBG : na
// } 

// { INDICATOR PLOTTING
lowBB=plot(math.exp(lowerBB),title='Low Band',color=color.aqua),plot(math.exp(bbandBasis),title='BBand Basis',color=color.red),
highBB=plot(math.exp(upperBB),title='High Band',color=color.aqua),fill(lowBB,highBB,title='Band Fill Color',color=color.rgb(0,128,128,75)) 
bgcolor(bullCol,title='Bullish Expansion Highlights'),bgcolor(bearCol,title='Bearish Expansion Highlights')
// } 
릴리즈 노트:
Adjusted Length title from
lenX = input(20,title='lenX')
to
 lenX = input(20,title='Length') 
in settings/menu.

Eric Thies
오픈 소스 스크립트

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

면책사항

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

차트에 이 스크립트를 사용하시겠습니까?