// Downloaded From https://www.WiseStockTrader.com
This technique is based on r-squared and linear regression slope indicators. The linear regression slope is AmiBroker's built-in function. The r-square indicator can be implemented as single-line function in AFL.

I am not the author. Found on internet

LISTING 1
Periods = Param("Periods", 20, 2, 200, 1, 10 ); 
Plot( LinRegSlope( C, Periods ), "LinRegSlope("+Periods+")", 
colorGreen, styleHistogram | styleThick ); 
LISTING 2
function RSquared( array, periods ) 
{ 
return Correlation( BarIndex(), array, periods ) ^ 2; 
} 
periods = Param("Periods", 20, 2, 100 ); 
Plot( RSquared( C, periods ), "R2(" + periods + ")", colorRed, styleThick );