Created
December 19, 2019 03:36
-
-
Save alexcrownjr/473b3cd4eade80772297dff2ff695255 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // @author LazyBear | |
| // RSI/MFI with Bollinger Bands. Dynamic Oversold/Overbought levels, yayy! | |
| // I add the BB period setting as told by John Bollinger's Book. | |
| study(title = "BB% of MFI/RSI [Modified from LazyBear]", shorttitle="BB%MFI/RSI[LB]") | |
| source = hlc3 | |
| length = input(14, minval=1), mult = input(2.0, minval=0.001, maxval=50), bblength = input(50, minval=1, title="BB Period") | |
| DrawRSI_f=input(true, title="Draw RSI?", type=bool) | |
| DrawMFI_f=input(false, title="Draw MFI?", type=bool) | |
| HighlightBreaches=input(true, title="Highlight Oversold/Overbought?", type=bool) | |
| DrawMFI = (not DrawMFI_f) and (not DrawRSI_f) ? true : DrawMFI_f | |
| DrawRSI = (DrawMFI_f and DrawRSI_f) ? false : DrawRSI_f | |
| // RSI | |
| rsi_s = DrawRSI ? rsi(source, length) : na | |
| plot(DrawRSI ? rsi_s : na, color=maroon, linewidth=2) | |
| // MFI | |
| upper_s = DrawMFI ? sum(volume * (change(source) <= 0 ? 0 : source), length) : na | |
| lower_s = DrawMFI ? sum(volume * (change(source) >= 0 ? 0 : source), length) : na | |
| mf = DrawMFI ? rsi(upper_s, lower_s) : na | |
| plot(DrawMFI ? mf : na, color=green, linewidth=2) | |
| // Draw BB on indices | |
| bb_s = DrawRSI ? rsi_s : DrawMFI ? mf : na | |
| basis = sma(bb_s, length) | |
| dev = mult * stdev(bb_s, bblength) | |
| upper = basis + dev | |
| lower = basis - dev | |
| plot(basis, color=red) | |
| p1 = plot(upper, color=blue) | |
| p2 = plot(lower, color=blue) | |
| fill(p1,p2, blue) | |
| b_color = (bb_s > upper) ? red : (bb_s < lower) ? green : na | |
| bgcolor(HighlightBreaches ? b_color : na) | |
| rsi_def = rsi(close, 14) | |
| buy_signals = crossover(bb_s, basis) //and rising(bb_s, 2) | |
| sell_signals = crossunder(rsi_def, 70) | |
| //plotshape(buy_signals, style=shape.triangleup, text="up 1") | |
| //plotshape(sell_signals, style=shape.triangledown, text="down 1") | |
| ph = pivothigh(rsi_s, 1,1) | |
| pl = pivotlow(rsi_s, 1,1) | |
| up1 = upper - bb_s | |
| plot(ph , style = cross, linewidth = 2, color = red, offset =-1, title ='test') | |
| plot(pl , style = cross, linewidth = 2, color = green, offset =-1) | |
| //plotshape(a, style=shape.triangledown, color=red) | |
| //plotshape(buy_signals, style=shape.triangleup, color=green) | |
| alertcondition(buy_signals, title='up', message='bb_s cross basis') | |
| alertcondition(sell_signals, title='rsi > 70', message='RSI is above 70') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment