+++++++++++
x = Cum(1);per = 5;s1=L;s11=H;
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
SU = IIf(x>startt-1,trendlineS,-1e10);
Plot(SU,"\nSU",colorYellow,styleThick);
Plot(C,"close",colorBlack,64);
+++++++++++++