//@version=4
study("Hesitation EMA", overlay=true)
// Inputs
length = input(14, minval=1, title="Length")
hesitation = input(0.5, minval=0, maxval=1, title="Hesitation")
// Exponential Moving Average (EMA) with hesitation smoothing
hesitation_ema = ema(close, length)
smoothed_ema = nz(hesitation_ema[1])
for i = 2 to bar_index
if abs(hesitation_ema[i] - hesitation_ema[i-1]) > hesitation * (high[i] - low[i])
smoothed_ema := nz(hesitation_ema[i])
else
smoothed_ema := nz(smoothed_ema[1])
plot(smoothed_ema, color=color.red, linewidth=1, title="Hesitation EMA")
// Arrows showing what the EMA trend would be without hesitation smoothing
for i = 1 to bar_index
if hesitation_ema[i] > hesitation_ema[i-1]
up = high
down = na
else if hesitation_ema[i] < hesitation_ema[i-1]
up = na
down = low
else
up = na
down = na
plotarrow(up, down, offset=-length)
I'm trying to write a control filter that plots an Exponential Moving Average (EMA) with the added feature of "hesitation smoothing". This means that the EMA line will be smoother and less prone to sudden changes, as the script will ignore small fluctuations that fall within a certain range, determined by the "hesitation" input variable. The script also plots blue arrows showing what the EMA trend would be without hesitation smoothing. and I'm getting an error which is beyond me.