Re: TradingView Indicators to MT4 Indicators

692
Mr. Tools, Kvak,

I kindly request you to convert the following TradingView indicator to MT4 and include support for all RSI types and averaging methods.

The indicator provides a normalized, non-linear momentum signal rather than relying on raw RSI values or simple RSI crossovers, which would be very useful for MT4 users seeking more accurate and noise-filtered momentum analysis. The histogram gives a clear bullish/bearish momentum bias that is easier to interpret than raw oscillators.

Thank you.


Code: Select all

//@version=5
indicator("Pro RSI Mean-Deviation Sigmoid Oscillator (Z-Score Normalized)", overlay=false)

// Parameters
rsiLength     = input.int(14, "RSI Period", minval=1)
emaLength     = input.int(14, "RSI EMA Period", minval=1)
stdevLength   = input.int(20, "Standard Deviation Period", minval=1)
sigmoidK      = input.float(1.0, "Sigmoid Sensitivity (k)", minval=0.1, maxval=10.0, step=0.1)
bbMultiplier  = input.float(2.0, "Bollinger Band Multiplier", minval=0.5, maxval=5.0, step=0.5)
showHistogram = input.bool(true, "Show Momentum Histogram")

// ================= Core Calculations =================

// RSI and EMA
rsiValue = ta.rsi(close, rsiLength)
rsiEma   = ta.ema(rsiValue, emaLength)

// Deviation and Z-Score
diff   = rsiValue - rsiEma
stdev  = ta.stdev(diff, stdevLength)
zScore = stdev != 0 ? diff / stdev : 0

// Sigmoid Mapping (0–100)
sigmoidRaw = 1 / (1 + math.exp(-sigmoidK * zScore))
sigmoid100 = sigmoidRaw * 100

// Momentum Strength (centered, relative)
momentumStrength = (sigmoid100 - 50) / 50   // -1 to +1

// ================= RSI Bollinger Bands =================

rsiBasis = ta.sma(rsiValue, stdevLength)
rsiStdev = ta.stdev(rsiValue, stdevLength)
rsiUpper = rsiBasis + bbMultiplier * rsiStdev
rsiLower = rsiBasis - bbMultiplier * rsiStdev

// ================= Reference Levels =================

// Sigmoid Levels
hline(50, "Sigmoid Midline", color=color.gray, linewidth=2)
hline(70, "Sigmoid Upper Threshold", color=color.new(color.green, 70), linestyle=hline.style_dotted)
hline(30, "Sigmoid Lower Threshold", color=color.new(color.red, 70), linestyle=hline.style_dotted)

// RSI Levels
hline(70, "RSI Overbought", color=color.new(color.orange, 80), linestyle=hline.style_dashed)
hline(30, "RSI Oversold", color=color.new(color.orange, 80), linestyle=hline.style_dashed)

// ================= Plots =================

// RSI Bollinger Bands
pUpper = plot(rsiUpper, "RSI Upper Band", color=color.new(color.blue, 70), linewidth=1)
pLower = plot(rsiLower, "RSI Lower Band", color=color.new(color.blue, 70), linewidth=1)
plot(rsiBasis, "RSI Basis", color=color.new(color.blue, 80), linewidth=1)
fill(pUpper, pLower, color=color.new(color.blue, 95), title="RSI Bollinger Area")

// RSI and RSI EMA
plot(rsiValue, "RSI", color=color.new(color.purple, 0), linewidth=2)
plot(rsiEma, "RSI EMA", color=color.new(color.orange, 0), linewidth=2)

// Sigmoid Oscillator (Primary Signal)
sigmoidColor = sigmoid100 >= 50 ? color.new(color.green, 0) : color.new(color.red, 0)
plot(sigmoid100, "Sigmoid Oscillator (0–100)", color=sigmoidColor, linewidth=5)

// Momentum Histogram
histColor = momentumStrength >= 0 ? color.new(color.green, 70) : color.new(color.red, 70)
histValue = showHistogram ? 50 + momentumStrength * 20 : na
plot(histValue, "Momentum Histogram", color=histColor, style=plot.style_histogram, linewidth=4)

// ================= Background Highlights =================

// Sigmoid Extremes
bgcolor(sigmoid100 > 70 ? color.new(color.green, 92) : na)
bgcolor(sigmoid100 < 30 ? color.new(color.red, 92) : na)

// RSI Bollinger Extremes
bgcolor(rsiValue > rsiUpper ? color.new(color.fuchsia, 95) : na, title="RSI BB Overbought")
bgcolor(rsiValue < rsiLower ? color.new(color.fuchsia, 95) : na, title="RSI BB Oversold")
Don't fight the market let it reveal its tricks, then strike with precision. 💪🥊