Re: MT4 Indicator requests and ideas

21272
dear mr.tools
possible to convert this TV code to mt4. I think its good one..
or is it any similar one in mt4, please share
// © BackQuant

//@version=5
indicator(
"Kalman Hull RSI [BackQuant]",
shorttitle = "∫KHRSI [BackQuant]",
overlay = false,
precision = 2,
timeframe = "",
timeframe_gaps = true
)



// Define User Inputs
series float pricesource = input.source(close, "Kalman Price Source", group = "Calculation")
simple float measurementNoise = input.float(3.0, title="Measurement Noise", group = "Calculation", tooltip = "Lookback Period/ Calculation Length", step = 1.0)
simple float processNoise = input.float(0.01, title="Process Noise", step = 0.01, group = "Calculation")
simple int rsiPeriod = input.int(12, "RSI Period", group = "Calculation")
simple bool showkalman = input.bool(true, "Show Oscillator?", group = "UI Settings")
simple bool paintCandles = input.bool(false, "Paint candles according to Trend?", group = "UI Settings")
simple bool showoboslvls = input.bool(true, "Show Static High and Low Levels (Extreme OB/ OS Thresholds)", group = "UI Settings")

/////////////////////////////////////////////////////////////// © BackQuant ///////////////////////////////////////////////////////////////
// Kalman Price Filter Function
N = 5
var float[] stateEstimate = array.new_float(N, na)
var float[] errorCovariance = array.new_float(N, 100.0)
f_init(series float pricesource) =>
if na(array.get(stateEstimate, 0))
for i = 0 to N-1
array.set(stateEstimate, i, pricesource)
array.set(errorCovariance, i, 1.0)

f_kalman(series float pricesource, float measurementNoise) =>
// Prediction Step
predictedStateEstimate = array.new_float(N)
predictedErrorCovariance = array.new_float(N)
for i = 0 to N-1
array.set(predictedStateEstimate, i, array.get(stateEstimate, i)) // Simplified prediction
array.set(predictedErrorCovariance, i, array.get(errorCovariance, i) + processNoise)

kalmanGain = array.new_float(N)
for i = 0 to N-1
kg = array.get(predictedErrorCovariance, i) / (array.get(predictedErrorCovariance, i) + measurementNoise)
array.set(kalmanGain, i, kg)
array.set(stateEstimate, i, array.get(predictedStateEstimate, i) + kg * (pricesource - array.get(predictedStateEstimate, i)))
array.set(errorCovariance, i, (1 - kg) * array.get(predictedErrorCovariance, i))

array.get(stateEstimate, 0)

f_init(pricesource)
kalmanFilteredPrice = f_kalman(pricesource, measurementNoise)
/////////////////////////////////////////////////////////////// © BackQuant ///////////////////////////////////////////////////////////////
// Hull Moving Average Function with Kalman instead of Weighted Moving Average
KHMA(_src, _length) =>
f_kalman(2 * f_kalman(_src, _length / 2) - f_kalman(_src, _length), math.round(math.sqrt(_length)))
// Return
kalmanHMA = KHMA(pricesource, measurementNoise)

kalman_hull_rsi = ta.rsi(kalmanHMA, rsiPeriod)


var color plotcol = #1dcaff4d

if kalman_hull_rsi > 50 and kalman_hull_rsi <= 55
plotcol := #1dcaff4d
else if kalman_hull_rsi > 55 and kalman_hull_rsi <= 62.5
plotcol := #1e9b254d
else if kalman_hull_rsi > 62.5 and kalman_hull_rsi <= 75
plotcol := #00ff003d
else if kalman_hull_rsi > 75 and kalman_hull_rsi <= 90
plotcol := #00ff0080
else if kalman_hull_rsi > 90
plotcol := #33ff00fc
else if kalman_hull_rsi < 50 and kalman_hull_rsi >= 45
plotcol := #e651004d
else if kalman_hull_rsi < 45 and kalman_hull_rsi >= 37.5
plotcol := #7715154d
else if kalman_hull_rsi < 37.5 and kalman_hull_rsi >= 25
plotcol := #ff00004d
else if kalman_hull_rsi < 25 and kalman_hull_rsi >= 10
plotcol := #ff000080
else if kalman_hull_rsi < 10
plotcol := #ff0000


plot(showkalman ? kalman_hull_rsi : na, style = plot.style_columns, histbase = 50, color = plotcol)
// Define Set Colors
osbgcol = #00e6764d
obbgcol = #ff52524d
obcol = #ff0000fc
oscol = #00ff00fc
midcol = #ffffff4d
barcolor = #00000000



// OB and OS Extreme Zones + Midline
obupper = plot(showoboslvls ? 100 : na , "+", obcol, editable = false)
osupper = plot(showoboslvls ? 20 : na , "-", oscol, editable = false)
oblower = plot(showoboslvls ? 80 : na , "+", obcol, editable = false)
oslower = plot(showoboslvls ? 0 : na , "-", oscol, editable = false)
fill(obupper, oblower, #7715154d, 'OB Fill')
fill(osupper, oslower, #1e9b254d, 'OS Fill')



// Colouring
var barColour = #ffffff
if kalman_hull_rsi > 50
barColour := #00ff00
else if kalman_hull_rsi < 50
barColour := #ff0000

// Plotting
barcolor(paintCandles ? barColour : na)

alertcondition(ta.crossover(kalman_hull_rsi, 50), title="Kalman Hull RSI Long", message="Kalman Hull RSI Long {{exchange}}:{{ticker}}")
alertcondition(ta.crossunder(kalman_hull_rsi, 50), title="Kalman Hull RSI Short", message="Kalman Hull RSI Short {{exchange}}:{{ticker}}")
"There is NO GOD higher than TRUTH" - Mahatma Gandhi


Re: MT4 Indicator requests and ideas

21277
tmostafa007 wrote: Fri May 09, 2025 11:11 am Dear All,

anyone can help me to enhance this code , i think there is a problem in the buffer and code as i need to create a dashboard that present the last bar color appear, also i need it to show me on the dashboard the next TF last bar color

thanks in advance
You can refer to the VZU Trading System developed by Mr. Vzulaks, as he has made enhancements to this indicator.
vzu-trading-system-t8475981.html