var Alfa = 0.05;
var ITrend[4];
function run()
{
StartDate = 2012;
EndDate = 2013;
BarPeriod = 1440;
var* Price = series(price());
//Fill Instantaneous Trendline at time 0, 1 and 2 with some
//values in the beginning of the testing period.
if (Bar < 4)
{
ITrend[0] = (Price[0] + 2 * Price[1] + Price[2])/4;
ITrend[1] = (Price[1] + 2 * Price[2] + Price[3])/4;
ITrend[2] = (Price[2] + 2 * Price[3] + Price[4])/4;
}
else
{
// Formula for Instantaneous Trendline itself after Bar 3.
ITrend[0] = (Alfa - Alfa * Alfa/4)*Price[0] + 0.5 * Alfa * Alfa * Price[1] - (Alfa - 0.75 * Alfa * Alfa)*Price[2]+2*(1-Alfa)*ITrend[1]-(1-Alfa)*(1-Alfa)*ITrend[2];
}
// Plot ITrend value
plot("ITrend",ITrend[0],0,RED);
// Plot ITrend values at time 0, 1 and 2 for troubleshooting.
plot("ITrend0",ITrend[0],NEW,RED);
plot("ITrend1",ITrend[1],0,BLUE);
plot("ITrend2",ITrend[2],0,YELLOW);
set(PLOTNOW);
}