expanding a bit on this same topic I post a cool little tool that extends a LSF (Least Squares Fit) calculated over certain time segment. Default is 1 segment, e.g. 1 day but the number can be set in Param window. It is actually intended for intraday price prediction assuming that yesterdays intraday trend continues today. The blue lines border the range where the price is expected to go, based on yesterdays trend. The blue lines are the lines you need to use for trading system development and they are stored in the arrays FitFinalExt, TopFinalExt and BotFinalExt. I did not add backtesting functionality in this version but was not able myself yet to make anything anywhere close to returning something decent. If you figure out some winning strategy send me an email, I particularly like those +500% per year systems 
/*
LSF Gadget, E.M.Pottasch, 10/2017
Calculates Least Squares Fit (LSF) over chosen time Segment / Interval (Day / Week / Month / Year)
The LSF is displayed in light Grey. The extension of the LSF (light blue) is displayed in the next
time segment and is supposed to function as the non-repainting indicator or price predictor.
The idea behind it is that yesterday's trend might continue today. Or if you set the "shft"
parameter at 1 then the hope is that the trend of the past 2 days (or 2 time segments) continues
today (or in the current time segment).
The extension of the fit is the price "predictor" and is stored in the arrays FitFinalExt, TopFinalExt,
BotFinalExt and can therefor be used for trading system developemnt
*/
sep = ParamList( "Separator Interval", "Day|Week|Month|Year", 0 );
order = Param( "Order", 1, 1, 8, 1 ); // order of LSF
clevel = Param( "Confidence Level", 2, 1, 3, 0.1 ); // standard deviation or width of channel
shft = Param( "Number of Time Segments for Trend calculation", 0, 0, 10, 1 ); // adds Time Segments for LSF calculation
maxpat = Param( "Maximum Number of Channels (Interval Segments)", 10, 0, 100, 1 ); // only has display purpose, by default max 10 patterns
moveback = Param( "Move Channel Pattern Back (Interval Segment)", 0, 0, 10, 1 ); // only has display purpose, move displayed patterns back
dif = 0;
Buy = Sell = Short = Cover = BuyPrice = SellPrice = ShortPrice = CoverPrice = 0;
Fit = Top = Bot = FitExt = TopExt = BotExt = Null;
FitFinalExt = TopFinalExt = BotFinalExt = Null;
FitFinal = TopFinal = BotFinal = Null;
switch( sep )
{
case "Day":
dn = Day();
dn1 = inDaily;
break;
case "Week":
dw = DayOfWeek();
newWeek = dw < Ref( dw, -1 );;
newYear = Year() != Ref( Year(), -1 );
dn = weekNumber = Sum( newWeek, BarsSince( newYear ) + 1 );
dn1 = inWeekly;
break;
case "Month":
dn = Month();
dn1 = inMonthly;
break;
case "Year":
dn = Year();
dn1 = inYearly;
break;
}
separator = dn != Ref( dn, -1 );
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
for( i = 0; i <= 2 + shft; i++ )
{
VarSet( "lbx" + i, ValueWhen( separator, bi, i ) );
}
prc = ( H + L ) / 2;
sd = 0;
Ext = lbx0 - lbx1;
Ext = IIf( Ext == 0 AND lbx1 == lbx0 AND lbx1 > 0 AND lbx0 > 0, BarCount - 1 - lbx1, Ext );
function get_y( eb, bars )
{
fb = eb - bars;
yy = Matrix( bars + 1, 1, 0 );
yy = MxSetBlock( yy, 0, bars, 0, 0, Ref( prc, fb ) );
return yy;
}
function get_x( eb, bars )
{
xx = Matrix( bars + 1, order + 1, 1 );
x = BarIndex() - bars / 2;
for( j = 1; j <= order; j++ )
{
xx = MxSetBlock( xx, 0, bars, j, j, x ^ j );
}
return xx;
}
function calculateCoefficients( eb, bars )
{
xx = get_x( eb, bars );
yy = get_y( eb, bars );
xxt = MxTranspose( xx );
aa = MxSolve( xxt @ xx, xxt ) @ yy;
return aa;
}
function calculateFit( eb, bars, Extend )
{
Fit = FitExt = Null;
lb = eb;
fb = eb - bars;
x = BarIndex() - bars / 2;
// calculate coefficients
aa = calculateCoefficients( eb, bars );
// store the fit in Fit
for( i = fb; i <= lb; i++ )
{
Fit[i] = aa[0][0];
for( j = 1; j <= order; j++ )
{
Fit[i] += aa[j][0] * x[ i - fb ] ^ j;
}
}
// calculate standard deviation
sdp = 0;
for( i = fb; i <= lb; i++ )
{
sdp = sdp + ( prc[i] - Fit[i] ) ^ 2;
}
sd = sqrt( sdp / ( bars - 2 ) ); // devide by ( bars - 2 ) corresponding to StdErr function
Top = Fit + sd * clevel;
Bot = Fit - sd * clevel;
// Extended fit
for( i = lb + 1; i <= Min( BarCount - 1, lb + Extend ); i++ )
{
FitExt[i] = aa[0][0];
for( j = 1; j <= order; j++ )
{
FitExt[i] += aa[j][0] * x[ i - fb ] ^ j;
}
}
TopExt = FitExt + sd * clevel;
BotExt = FitExt - sd * clevel;
}
function doCalculation( fb, lb )
{
cnt = 0; // count number of visible periods
Extend = Ext[lb];
for( i = lb; i > fb; i-- )
{
if( !separator[i] )
{
hh = VarGet( "lbx" + ( 1 + shft ) );
eb = i;
sb = hh[i];
jmp = lbx1[i];
bars = eb - sb + 0;
if( IsEmpty( bars ) ) break;
calculateFit( eb, bars, Extend );
FitFinalExt = IIf( !IsEmpty( FitExt ), FitExt, FitFinalExt );
TopFinalExt = IIf( !IsEmpty( TopExt ), TopExt, TopFinalExt );
BotFinalExt = IIf( !IsEmpty( BotExt ), BotExt, BotFinalExt );
FitFinal = IIf( !IsEmpty( Fit ), Fit, FitFinal );
TopFinal = IIf( !IsEmpty( Top ), Top, TopFinal );
BotFinal = IIf( !IsEmpty( Bot ), Bot, BotFinal );
if( Status( "Action" ) == actionIndicator ) // control the display of the channels in here
{
if( cnt >= moveback AND( cnt <= maxpat + moveback ) )
{
line = Null;
line = IIf( !IsEmpty( Top ), Top, line );
Plot( line, "", ColorRGB( 90, 90, 90 ), styleLine | styleNoLabel | styleNoRescale, Null, Null, 0, 0, 1 );
line = IIf( !IsEmpty( Bot ), Bot, line );
Plot( line, "", ColorRGB( 90, 90, 90 ), styleLine | styleNoLabel | styleNoRescale, Null, Null, 0, 0, 1 );
line = IIf( !IsEmpty( Fit ), Fit, line );
Plot( line, "", ColorRGB( 50, 50, 50 ), styleDashed | styleNoLabel | styleNoRescale, Null, Null, 0, 0, 1 );
}
if( cnt > moveback AND( cnt <= maxpat + moveback ) )
{
line = Null;
line = IIf( !IsEmpty( TopExt ) AND TopExt, TopExt, line );
Plot( line, "", ColorRGB( 0, 250, 250 ), styleLine | styleNoLabel | styleNoRescale, Null, Null, 0, 0, 2 );
line = IIf( !IsEmpty( BotExt ) AND BotExt, BotExt, line );
Plot( line, "", ColorRGB( 0, 250, 250 ), styleLine | styleNoLabel | styleNoRescale, Null, Null, 0, 0, 2 );
}
}
}
else
{
jmp = i;
}
i = jmp;
Extend = Ext[i];
cnt++;
}
}
if( Status( "Action" ) == actionIndicator )
{
dif = int( lvb - fvb );
SetBarsRequired( dif * 2, dif * 2 );
SetChartBkColor( colorBlack );
SetChartOptions( 1, chartShowDates, chartGridMiddle, 0, 0, 0 );
SetBarFillColor( IIf( C > O, ColorRGB( 0, 75, 0 ), IIf( C <= O, ColorRGB( 75, 0, 0 ), colorLightGrey ) ) );
Plot( C, "", IIf( C > O, ColorRGB( 0, 255, 0 ), IIf( C <= O, ColorRGB( 255, 0, 0 ), colorLightGrey ) ), 64, Null, Null, 0, 0, 1 );
Plot( separator, "", colorDarkBlue, styleHistogram | styleOwnScale | styleNoLabel | styleNoRescale, 0, 1, 0, -2, 5 );
doCalculation( fvb, lvb );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorDarkGreen, 0, L, -15 );
PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, -15 );
PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorwhite, 0, SellPrice, 0 );
PlotShapes( IIf( Short, shapeSmallDownTriangle, shapeNone ), colorRed, 0, H, IIf( Short AND Sell, -30, -15 ) );
PlotShapes( IIf( Short, shapeSmallCircle, shapeNone ), colorWhite, 0, ShortPrice, 0 );
PlotShapes( IIf( Cover, shapeSmallUpTriangle, shapeNone ), colorDarkGreen, 0, L, IIf( Cover AND Buy, -30, -15 ) );
PlotShapes( IIf( Cover, shapeSmallCircle, shapeNone ), colorwhite, 0, CoverPrice, 0 );
}