// Downloaded From https://www.WiseStockTrader.com
//Stocks trading in a tight range 
//You may want to try the code below to find stocks that are trading in a range OR band.
//The idea is to take a look at the Highest closing price AND the Lowest
//closing price over x days, determine how tight that trading range has been.
//I Use the code to find breakouts (UP/DOWN)from these ranges.

RP = Param("Trading Range Period" , 30, 10, 240, 1);
MRB = Param("Max Range Band in %" , 20, 1, 30, 1);

// Calculate the trading Range Band ------------ --
RBH = Ref(HHV(Close, RP), -1); // Highest Close over Range Period
//(Preceeding RP days)
RBL = Ref(LLV(Close, RP), -1); // Lowest Close over Range Period
//(Preceeding RP days)
RBP = ((RBH - RBL) / RBH) * 100; // Range Band in percentage
IRB = RBP <= MRB; // Range Band % less than Max RB %
CBRup = C > RBH; // Close above Range Band?
CBRdn = C < RBL; // Close above Range Band?

Filter=IRB AND (CBRup OR CBRdn);

AddColumn(IIf(IRB,RBP,Null) , "RBP" , 3.2, colorWhite, colorDarkYellow, 50); 
AddColumn(IIf(CBRup,1,IIf(CBRdn,-1,Null)) , "C" , 3.2, colorWhite,IIf(CBRup,colorDarkGreen,IIf(CBRdn,colorDarkRed,Null)), 50);