sh3rmfx

Bollinger Fanboy v2.0

3
By using this script you agree that the author will not be liable for any losses financial or otherwise from the use of this script.

Copyright Michael Edwards 2014 (bollingerfanboy.com)
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
study(title="Bollinger Fanboy", shorttitle="Bollinger Fanboy", overlay=true)
bf_spread = input(title="Spread", type=float, defval=0.0000)
bf_period = input(title="Period", type=integer, defval=20)
bf_stddev = input(title="Standard Deviation", type=integer, defval=2)
bf_profit = input(title="Profit Ratio", type=float, defval=1.50)

bf_middle = sma(close, bf_period)
bf_top = bf_middle + (stdev(close, bf_period) * bf_stddev)
bf_bottom = bf_middle - (stdev(close, bf_period) * bf_stddev)

bf_height = ((high + bf_spread) - (low - bf_spread)) * bf_profit

bf_short_entry = low - bf_spread
bf_short_stop = high + bf_spread
bf_short_exit = bf_short_entry - bf_height

bf_long_entry = high + bf_spread
bf_long_stop = low - bf_spread
bf_long_exit = bf_long_entry + bf_height

bf_long = close < bf_middle ? (close > bf_bottom ? true : false) : false
bf_short = close > bf_middle ? (close < bf_top ? true : false) : false

bf_lowest = low == lowest(bf_period / 2) ? ( low < bf_bottom ? true : false ) : false
bf_highest = high == highest(bf_period / 2) ? ( high > bf_top ? true : false ) : false

bf_go_long = bf_long ? ( bf_lowest ? ( bf_long_exit < (bf_middle - bf_spread) ? true : false ) : false ) : false
bf_go_short = bf_short ? ( bf_highest ? ( bf_short_exit > (bf_middle + bf_spread) ? true : false ) : false ) : false

bf_enter = bf_go_long ? bf_long_entry : ( bf_go_short ? bf_short_entry : bf_enter[1] )
bf_exit = bf_go_long ? bf_long_exit : ( bf_go_short ? bf_short_exit : bf_exit[1] )
bf_stop = bf_go_long ? bf_long_stop : ( bf_go_short ? bf_short_stop : bf_stop[1] )

plot(bf_enter == bf_enter[bf_period] ? na : bf_enter, title="Entry", color=orange, style=circles, linewidth=2)
plot(bf_enter == bf_enter[bf_period] ? na : bf_exit, title="Exit", color=green, style=circles, linewidth=2)
plot(bf_enter == bf_enter[bf_period] ? na : bf_stop, title="Stop", color=red, style=circles, linewidth=2)