Linear Regression Curve

Need help in coding the below formula.

len = input(13)

w= input (4)

lrc = linearregressioncurve( (high+close)/2, len, 0)

lrccolor = change(lrc)>=0 ? lime : red

plot(lrc,color=lrccolor)

plot(w>=4?lrc:na, offset=4,color=lrccolor)

plot(w>=3?lrc:na, offset=3,color=lrccolor)

plot(w>=-4?lrc:na, offset=-4,color=lrccolor)

plot(w>=-3?lrc:na, offset=-3,color=lrccolor)

Linear Regression Slope we can write in transcript like,

SLOPE(CLOSE, 30) > 0.3

Linear Regression Curve function is not there in tradescript,