Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- //This indicator is designed to show give early entry signals as well as to follow trend moves, according to different settings.
- //
- //The indicator shows a histogram of the RSI ro MFI in relation to an ema of the RSI or MFI.
- //The histogram is then smoothed to give early reversal/entry signals.
- //The actual RSI/MFI line with oversold/overbought indication can be displayed or omitted, as preferred.
- //in addition to the RSI/MFI line or as an alternative to it, the background colour can be set to change folowing the RSI/MFI signals.
- //The timeframe can be chosen. Higher timeframes (eg. 3h) tend to give less false signals.
- //
- //@version=5
- //added support for custom Multiple Time Frame selection.
- //added option for choice of RSI or MFI as base indicator.
- //added option for price bar coloring according to the indicator. (deselecting "borders" in the "style" tab is recommended)
- //price bar coloring can be adjusted for different strategies:
- //1. following the slope of the histogram (for faster entry/exit signals)
- //2. according to positive or negative histogram (for longer moves)
- //3. according to pos. or neg. RSI/MFI (for longer term trend holds)
- //4. uptrend: biased towards faster buy signals and slower sell signals to stay in the uptrend
- //5. downtrend: biased towards faster sell signals and slower buy signals to stay in the downtrend
- //
- //A longer timeframe (eg. 3x) is recommended for following trend moves.
- //try different strategies to see what works better for RSI or MFI.
- //
- //JD.
- indicator(title='RSI/MFI - MTF - Entry signals/Trend colored bars - JD', shorttitle='RSI/MFI - MTF - Entry signals/Trend colored bars - JD')
- useCurrentRes = input(false, title='Use Current Chart Resolution?')
- resCustom = input.timeframe(title='Use Different Timeframe? Uncheck Box Above', defval='180')
- show_mfi = input.int(1, minval=1, maxval=2, title='base indicator: 1= RSI, 2= MFI')
- src = close
- len = input.int(14, minval=1, title='RSI/MFI Length')
- len2 = input.int(4, minval=1, title='Smoothing Length')
- th1 = input.int(70, minval=1, title='overbought')
- th2 = input.int(30, minval=1, title='oversold')
- show_rsi = input(true, title='show RSI or MFI line')
- show_bg = input(false, title='show RSI or MFI background color')
- color_bars = input(false, title='color pricebars')
- color_base = input.int(1, minval=1, maxval=5, title='color bars based on: 1= histogram slope, 2=+/- histogram, 3=+/- rsi/mfi-line, 4= uptrend (sell bias), 5= downtrend (buy bias)')
- res = useCurrentRes ? timeframe.period : resCustom
- //MFI calcutaion
- TypPrice = hlc3
- upper_s = math.sum(volume * (ta.change(TypPrice) <= 0 ? 0 : TypPrice), len)
- lower_s = math.sum(volume * (ta.change(TypPrice) >= 0 ? 0 : TypPrice), len)
- mf = 100.0 - 100.0 / (1.0 + upper_s / lower_s)
- //RSI/MFI selection
- rsi_1 = ta.rsi(src, len)
- rsi_base = show_mfi == 1 ? rsi_1 : mf
- //output MTF
- rsi = request.security(syminfo.tickerid, res, rsi_base)
- smooth_base = ta.ema(rsi_base, len)
- smooth = request.security(syminfo.tickerid, res, smooth_base)
- smooth2 = ta.ema(rsi - smooth, len2)
- smooth_up = smooth >= smooth[1] ? true : false
- smooth2_up = smooth2 >= smooth2[2] ? true : false
- histo = rsi - smooth
- //color definition
- color_1 = color.new(color.green, 0)
- color_2 = color.new(color.green, 50)
- emacolor = histo >= 0 ? smooth2_up ? color_1 : color_2 : smooth2_up ? color.maroon : color.red
- smooth2color = smooth2 >= smooth2[2] ? color.green : color.red
- color_3 = color.new(color.red, 75)
- color_4 = color.new(color.maroon, 85)
- color_5 = color.new(color.lime, 85)
- color_6 = color.new(color.green, 90)
- bcol = rsi < 50 ? rsi < th2 ? color_3 : color_4 : rsi > 50 ? rsi > th1 ? color_5 : color_6 : na
- color_7 = color.new(color.maroon, 85)
- color_8 = color.new(color.maroon, 20)
- color_9 = color.new(color.lime, 85)
- color_10 = color.new(color.green, 90)
- color_11 = color.new(color.green, 30)
- rsicol = bcol == color.new(color.red, 75) ? color.red : bcol == color_7 ? color_8 : bcol == color_9 ? color.lime : bcol == color_10 ? color_11 : na
- plot(rsi - smooth, title='RSI - histo', style=plot.style_histogram, color=emacolor, linewidth=2, transp=0)
- plot(smooth2, title='RSI - ma', color=smooth2color, linewidth=3, transp=20)
- plot(show_rsi ? rsi - 50 : na, linewidth=2, color=rsicol, transp=0)
- bgcolor(title='RSI overbought/oversold', color=show_bg ? bcol : na, transp=90)
- barcolor_ref = color_base == 1 ? smooth2color : color_base == 2 ? histo >= 0 ? color.green : color.red : color_base == 3 ? rsi >= 50 ? color.green : color.red : color_base == 4 ? histo <= 0 ? smooth2color : color.green : color_base == 5 ? histo >= 0 ? smooth2color : color.red : na
- color_12 = color.new(color.lime, 30)
- color_13 = color.new(color.red, 20)
- barc = barcolor_ref == color.green ? color_12 : color_13
- barcolor(color_bars ? barc : na)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement