View source
//@version=6
indicator(
"R//R · 4 EMA + SMA · RSI / MFI",
shorttitle = "R//R MA + RSI/MFI",
overlay = false,
precision = 2
)
// ╔══════════════════════════════════════════════════════════════════════════╗
// ║ R//R · 4 EMA + SMA · RSI / MFI ║
// ║ ║
// ║ PRICE CHART: Four editable EMAs and one editable SMA. ║
// ║ LOWER PANE: RSI and MFI together on the same 0–100 scale. ║
// ║ ║
// ║ R//R principle: moving averages show structure; RSI and MFI show ║
// ║ momentum and money-flow condition inside that structure. ║
// ╚══════════════════════════════════════════════════════════════════════════╝
// ============================================================================
// 01 · MOVING AVERAGES — DISPLAYED ON THE MAIN PRICE CHART
// ============================================================================
groupMA = "01 · Moving averages"
maSource = input.source(close, "MA source", group = groupMA)
// EMA 1
showEMA1 = input.bool(true, "Show EMA 1", group = groupMA, inline = "ema1")
ema1Length = input.int(9, "Length", minval = 1, group = groupMA, inline = "ema1")
ema1Color = input.color(color.aqua, "Colour", group = groupMA, inline = "ema1")
// EMA 2
showEMA2 = input.bool(true, "Show EMA 2", group = groupMA, inline = "ema2")
ema2Length = input.int(21, "Length", minval = 1, group = groupMA, inline = "ema2")
ema2Color = input.color(color.yellow, "Colour", group = groupMA, inline = "ema2")
// EMA 3
showEMA3 = input.bool(true, "Show EMA 3", group = groupMA, inline = "ema3")
ema3Length = input.int(50, "Length", minval = 1, group = groupMA, inline = "ema3")
ema3Color = input.color(color.orange, "Colour", group = groupMA, inline = "ema3")
// EMA 4
showEMA4 = input.bool(true, "Show EMA 4", group = groupMA, inline = "ema4")
ema4Length = input.int(200, "Length", minval = 1, group = groupMA, inline = "ema4")
ema4Color = input.color(color.fuchsia, "Colour", group = groupMA, inline = "ema4")
// SMA
showSMA = input.bool(true, "Show SMA", group = groupMA, inline = "sma")
smaLength = input.int(200, "Length", minval = 1, group = groupMA, inline = "sma")
smaColor = input.color(color.white, "Colour", group = groupMA, inline = "sma")
// Average calculations
ema1 = ta.ema(maSource, ema1Length)
ema2 = ta.ema(maSource, ema2Length)
ema3 = ta.ema(maSource, ema3Length)
ema4 = ta.ema(maSource, ema4Length)
sma = ta.sma(maSource, smaLength)
// Force these plots onto the main price chart.
plot(
showEMA1 ? ema1 : na,
title = "EMA 1",
color = ema1Color,
linewidth = 2,
force_overlay = true
)
plot(
showEMA2 ? ema2 : na,
title = "EMA 2",
color = ema2Color,
linewidth = 2,
force_overlay = true
)
plot(
showEMA3 ? ema3 : na,
title = "EMA 3",
color = ema3Color,
linewidth = 2,
force_overlay = true
)
plot(
showEMA4 ? ema4 : na,
title = "EMA 4",
color = ema4Color,
linewidth = 2,
force_overlay = true
)
plot(
showSMA ? sma : na,
title = "SMA",
color = smaColor,
linewidth = 2,
force_overlay = true
)
// ============================================================================
// 02 · RSI + MFI — SHARED 0–100 SCALE IN THIS LOWER PANE
// ============================================================================
groupOsc = "02 · RSI + MFI"
// RSI controls
showRSI = input.bool(true, "Show RSI", group = groupOsc, inline = "rsi")
rsiSource = input.source(close, "Source", group = groupOsc, inline = "rsi")
rsiLength = input.int(14, "Length", minval = 1, group = groupOsc, inline = "rsi")
rsiColor = input.color(color.aqua, "Colour", group = groupOsc, inline = "rsi")
// MFI controls
showMFI = input.bool(true, "Show MFI", group = groupOsc, inline = "mfi")
mfiSource = input.source(hlc3, "Source", group = groupOsc, inline = "mfi")
mfiLength = input.int(14, "Length", minval = 1, group = groupOsc, inline = "mfi")
mfiColor = input.color(color.orange, "Colour", group = groupOsc, inline = "mfi")
// Oscillator display controls
showMidline = input.bool(true, "Show 50 midpoint", group = groupOsc)
showZones = input.bool(true, "Shade 70 / 30 extreme zones", group = groupOsc)
// Calculations
rsi = ta.rsi(rsiSource, rsiLength)
mfi = ta.mfi(mfiSource, mfiLength)
// RSI and MFI occupy the same lower 0–100 pane.
plot(
showRSI ? rsi : na,
title = "RSI",
color = rsiColor,
linewidth = 2
)
plot(
showMFI ? mfi : na,
title = "MFI",
color = mfiColor,
linewidth = 2
)
// ============================================================================
// 03 · RSI / MFI REFERENCE LEVELS
// ============================================================================
upperLevel = hline(
70,
"70 · Upper extreme",
color = color.new(color.red, 35),
linestyle = hline.style_dashed
)
midLevel = hline(
50,
"50 · Midpoint",
color = showMidline ? color.new(color.gray, 55) : color.new(color.gray, 100),
linestyle = hline.style_dotted
)
lowerLevel = hline(
30,
"30 · Lower extreme",
color = color.new(color.lime, 35),
linestyle = hline.style_dashed
)
topBound = hline(
100,
"100",
color = color.new(color.gray, 100)
)
bottomBound = hline(
0,
"0",
color = color.new(color.gray, 100)
)
fill(
upperLevel,
topBound,
color = showZones ? color.new(color.red, 92) : na,
title = "Upper extreme zone"
)
fill(
bottomBound,
lowerLevel,
color = showZones ? color.new(color.lime, 92) : na,
title = "Lower extreme zone"
)
// ============================================================================
// 04 · OPTIONAL RSI / MFI RELATIONSHIP SIGNALS
// ============================================================================
groupSignals = "03 · RSI / MFI relationship"
showCrosses = input.bool(false, "Show RSI / MFI crosses", group = groupSignals)
showAgreement = input.bool(false, "Show RSI / MFI agreement background", group = groupSignals)
rsiCrossUp = ta.crossover(rsi, mfi)
rsiCrossDown = ta.crossunder(rsi, mfi)
bothBullish = rsi > 50 and mfi > 50
bothBearish = rsi < 50 and mfi < 50
plotshape(
showCrosses and rsiCrossUp,
title = "RSI crosses above MFI",
style = shape.triangleup,
location = location.bottom,
color = color.aqua,
size = size.tiny,
text = "R↑"
)
plotshape(
showCrosses and rsiCrossDown,
title = "RSI crosses below MFI",
style = shape.triangledown,
location = location.top,
color = color.orange,
size = size.tiny,
text = "R↓"
)
bgcolor(
showAgreement
? bothBullish
? color.new(color.lime, 92)
: bothBearish
? color.new(color.red, 92)
: na
: na,
title = "RSI / MFI agreement"
)
// ============================================================================
// 05 · ALERT CONDITIONS
// ============================================================================
alertcondition(
rsiCrossUp,
title = "R//R · RSI crosses above MFI",
message = "R//R: RSI has crossed above MFI."
)
alertcondition(
rsiCrossDown,
title = "R//R · RSI crosses below MFI",
message = "R//R: RSI has crossed below MFI."
)
alertcondition(
ta.crossover(rsi, 50),
title = "R//R · RSI crosses above 50",
message = "R//R: RSI has crossed above the 50 midpoint."
)
alertcondition(
ta.crossunder(rsi, 50),
title = "R//R · RSI crosses below 50",
message = "R//R: RSI has crossed below the 50 midpoint."
)
alertcondition(
ta.crossover(mfi, 50),
title = "R//R · MFI crosses above 50",
message = "R//R: MFI has crossed above the 50 midpoint."
)
alertcondition(
ta.crossunder(mfi, 50),
title = "R//R · MFI crosses below 50",
message = "R//R: MFI has crossed below the 50 midpoint."
)