Ehlers Instantaneous Trend [LazyBear]

Code
var nz(var x, var y) {
	if (x != 0) return x;
	return y;	
}

function run() 
{
	set(PLOTNOW);
	StartDate = 20220114;
	BarPeriod = 1;
	LookBack = 100;
	BarMode = BR_FLAT;

	vars src = series(price());
	var a = .07;
	vars it = series(0, 3);
	it[0] =
		(a-((a*a)/4.0))*src[0]+0.5*a*a*src[1]
		-(a-0.75*a*a)*src[2]+2*(1-a)*nz(it[1], ((src[0]+2*src[1]+src[2])/4.0))
		-(1-a)*(1-a)*nz(it[2], ((src[0]+2*src[1]+src[2])/4.0));
	var lag=2.0*it[0]-it[2];
	plot("trend", it[0], MAIN, RED);
	plot("trigger", lag, MAIN, BLUE);
}


weird crap starts to happen once I try to extract a function

(original code)

Code
//
// @author LazyBear 
// 
// List of my public indicators: http://bit.ly/1LQaPK8 
// List of my app-store indicators: http://blog.tradingview.com/?p=970 
//
study(title="Ehlers Instantaneous Trend [LazyBear]", shorttitle="EIT_LB", overlay=true, precision=3)
src=input(hl2, title="Source")
a= input(0.07, title="Alpha", step=0.01) 
fr=input(false, title="Fill Trend Region")
ebc=input(false, title="Enable barcolors")
hr=input(false, title="Hide Ribbon")
it=(a-((a*a)/4.0))*src+0.5*a*a*src[1]-(a-0.75*a*a)*src[2]+2*(1-a )*nz(it[1], ((src+2*src[1]+src[2])/4.0))-(1-a )*(1-a )*nz(it[2], ((src+2*src[1]+src[2])/4.0))
lag=2.0*it-nz(it[2])
dl=plot(fr and (not hr)?(it>lag?lag:it):na, color=gray, style=circles, linewidth=0, title="Dummy")
itl=plot(hr?na:it, color=fr?gray:red, linewidth=1, title="Trend")
ll=plot(hr?na:lag, color=fr?gray:blue, linewidth=1, title="Trigger")
fill(dl, ll, green, title="UpTrend", transp=70)
fill(dl, itl, red, title="DownTrend", transp=70)
bc=not ebc?na:(it>lag?red:lime)
barcolor(bc)



(proof pictures)

[Linked Image]
[Linked Image]


wanted to try out how hard it is to convert a Pine script

Last edited by Lapsa; 01/15/22 02:21.