# Leavitt, Jay A., PhD [2017]. “Beyond The Hull With Leavitt Projections,” Technical Analysis of StockS & commoditieS, Volume 35: February.

## orig n was 20

script LeavittProjection{

input y = close;

input n = 8;

rec x = x[1] + 1;

def a = (n * sum(x * y, n) - sum(x, n) * sum(y, n) ) / ( n *sum(Sqr(x), n) - Sqr(sum(x, n)));

def b = (sum(Sqr(x), n) * sum(y, n) - sum(x, n) * sum(x *y, n) ) / ( n * sum(Sqr(x), n) - Sqr(sum(x, n)));

plot LeavittProjection= a*x+ b;

}

script LeavittConvolution

{ input price = close;

input n = 13;

def intLength = Floor(Sqrt);

plot LeavittConvolution = LeavittProjection (LeavittProjection (price, n), intLength);

}

def price = Close;

input length = 8;

def intLength = Floor(Sqrt(length));

plot LeavittConvolution = LeavittProjection (LeavittProjection (price, length), intLength);

LeavittConvolution.AssignValueColor(if LeavittConvolution > LeavittConvolution [1] then Color.blue else if LeavittConvolution < LeavittConvolution [1] then Color.RED else color.white);

leavittConvolution.setlineweight(2);

leavittConvolution.hidebubble();

addlabel(1,"leavit " + round(leavittConvolution,2), if LeavittConvolution > LeavittConvolution [1] then Color.blue else if LeavittConvolution < LeavittConvolution [1] then Color.RED else color.white);