Indicator designed to implement a trading indicator combining a Hull Moving Average (HMA) with a Kahlman filter, used to identify trends and potential buy/sell signals in a financial market. Let’s break it down into simpler terms:
length, showcross, gain, k, nonrepainting are variables that can be adjusted to modify how the indicator behaves.src represents the source data, typically the closing price of a trading instrument.hma3, based on the closing price (close). These calculations use weighted averages over different periods to reduce lag and increase responsiveness.Pred, Velo, Smooth.kf) from the noisy input data (src).a and b without Kalman filter) and another using the Kalman-filtered price (a and b with Kalman filter).showcross is true, the script looks for crossover points between a and b — these are points where the two lines cross each other.a crosses over b, it’s marked as a “sell” signal (S), and when a crosses under b, it’s marked as a “buy” signal (B).DRAWTEXT, DRAWPOINT) to visually represent buy and sell signals on the chart for easier interpretation.//variables
length=24
showcross=1
nonrepainting=0
src=customclose
length =length
showcross = showcross
gain = gain
k = k
hma= WeightedAverage[ROUND(SQRT(length))](2 * WeightedAverage[ROUND(length / 2)](src) - WeightedAverage[length](src))
// Calcul des composants de l'indicateur HMA3
p=(length/2)
wma1 = WeightedAverage[round(p/3)](close)
wma2 = WeightedAverage[round(p/2)](close)
wma3 = WeightedAverage[round(p)](close)
// Calcul de l'indicateur HMA3
ga=3*wma1-wma2-wma3
hma3 = WeightedAverage[round(p)](ga)
// Initialisation des variables du filtre de Kalman
ONCE Pred = src
ONCE Velo = 0
ONCE Smooth = src
kf = src
// Boucle de calcul pour le filtre de Kalman
IF BarIndex > 0 THEN
Smooth = Pred + (src-Pred)*SQRT((gain/10000)*2)
Velo=Velo+((gain/10000)*(src-Pred))
Pred=Smooth+Velo
kf=Pred
ENDIF
wma1f = WeightedAverage[round(p/3)](kf)
wma2f = WeightedAverage[round(p/2)](kf)
wma3f = WeightedAverage[round(p)](kf)
// Calcul du filtrage de b
gaf=3*wma1f-wma2f-wma3f
if k then
a =WeightedAverage[ROUND(SQRT(length))](2 * WeightedAverage[ROUND(length / 2)](kf) - WeightedAverage[length](kf))
b =WeightedAverage[round(p)](gaf)
endif
if not k then
a = hma
b = hma3
endif
if showcross then
crossdn =a crosses over b
atrh = averagetruerange[10](close)*0.5
if nonrepainting=0 then
if crossdn then
DRAWTEXT("S", barindex-1,high[1]+atrh,dialog,bold,14)coloured(155,0,0)
DRAWPOINT(barindex-1,high[1]+atrh,4)coloured(255,255,255,100)bordercolor(0,155,0,250)
endif
crossup = a crosses under b
if crossup then
DRAWTEXT("B", barindex-1,b[1]-atrh,dialog,bold,14)coloured(0,155,0)
DRAWPOINT(barindex-1,b[1]-atrh,4)coloured(255,255,255,100)bordercolor(155,0,0,250)
endif
endif
if nonrepainting=1 then
if crossdn then
DRAWTEXT("S", barindex,high+atrh,dialog,bold,14)coloured(155,0,0)
DRAWPOINT(barindex,high+atrh,4)coloured(255,255,255,100)bordercolor(0,155,0,250)
endif
crossup = a crosses under b
if crossup then
DRAWTEXT("B", barindex,b-atrh,dialog,bold,14)coloured(0,155,0)
DRAWPOINT(barindex,b-atrh,4)coloured(255,255,255,100)bordercolor(155,0,0,250)
endif
endif
endif
return a as "hull",b as "hull3"