Help with Linear Regression scanner

eaniles

New member
VIP
Hey All. First time poster. Would appreciate some help on this.

I am trying to create a scan where results populate based on the Linear Regression channel Upper and Lower limits.

To be more specific:
  • Price close is near or crosses above the UpperLimit
  • Price close is near or crosses below the LowerLimit
So far I have come up with the following. Not sure if it is correct.
Any of the following condition:
Code:
Between(LinearRegCh100()."UpperLR",close, close * 1.05)
Code:
Between(LinearRegCh100()."LowerLR", close * .95, close )

Any corrections or improvements would be appreciated.

Some additional thoughts would be that I would like to scan for multiple bounces off the limit lines which might be an entry/exit signal.

Thanks
 

hockeycoachdoug

Member
2019 Donor
VIP
might want to add slope of the linear regression line. I used to use Stockfetcher for scans and had one that followed stocks that had a positive slope and the price was at the bottom of the channel and vice versa. Thus buying pullbacks in an up move and selling rips in a downturn
 

XeoNoX

Well-known member
VIP
because linear regression changes due to chart time frame, you must manually specify the bars back you want to be scanned for and your chart will have to match. There has been this topic of scanning against linear regression on this forum already, Please use the search feature.
@BenTen can move this topic to existing thread
 
Last edited:

XeoNoX

Well-known member
VIP
here are some examples however:


Code:
#LinearRegChVar scan
# Mobius©: GldMtn  this is a scan I have in a dynamic watch list with my favorite companies to trade.
#It works very well as a signal when a #company is moving up through resistance in a trough or lower area. For a long trade.
Plot scan = low crosses LinearRegChVar ("width of channel" = 69, "full range" = no, "length" = 252)."LowerLR"

Code:
#Mob channel scan
# Mobius©: Ralf - here is a channel scan
# LRC Variable Scan
input price = hl2;
input n = 252;
input widthOfChannel = 69;
def MidLine = InertiaAll(price, n);
def dist = HighestAll(AbsValue(MidLine - price)) * (widthOfChannel / 100.0);
# Scan only allows one plot. Set plot to Upper or Lower and def to the other
def "Upper Band Cross"  = close crosses MidLine + dist;
plot "Lower Band Cross" = close crosses MidLine - dist;


Code:
#Mr. Script:
#scan for declining LR
def input price = close;
def MiddleLR = Inertia(price,20);
plot scan = isDescending(MiddleLR);
 

eaniles

New member
VIP
Thanks for the help XeoNox. I have been messing around today in thinkScript trying to incorporate the existing scans and LR slope. This is what I have come up with.

Bullisth Entry Scanner
Code:
input price = close;
input sLenght = 14;

def LRS = 6 * ( WMA(price, sLenght) -  Average(price, sLenght) ) / (sLenght - 1);


def MiddleLR = InertiaAll(price);
def dist = HighestAll(AbsValue(MiddleLR - price));
def UpperLR = MiddleLR + dist;
def LowerLR = MiddleLR - dist;
def offset = Round((UpperLR - LowerLR)* .11, 3);
def LowerLR_offset = LowerLR + offset;
def risingLRS = LRS[1] <= LRS;
def lowZone = price <= LowerLR_offset within 1 bars;
plot bullEntry = lowZone and risingLRS;


Bearish Entry Scanner
Code:
input price = close;
input sLenght = 14;

def LRS = 6 * ( WMA(price, sLenght) -  Average(price, sLenght) ) / (sLenght - 1);


def MiddleLR = InertiaAll(price);
def dist = HighestAll(AbsValue(MiddleLR - price));
def UpperLR = MiddleLR + dist;
def LowerLR = MiddleLR - dist;
def offset = Round((UpperLR - LowerLR)* .11, 3);
def UpperLR_offset = UpperLR - offset;
def droppingLRS = LRS[1] >= LRS;
def upperZone = price >= UpperLR_offset within 5 bars;
plot bearEntry = upperZone and droppingLRS;

Essentially I am defining a 10% offset from the upper or lower line and then utilizing the LR slope to attempt to find candidates. LR slope is inspected to determine if the previous LRS is below/above current depending on scan.

I also created an indicator for this on the chart. I am sure its not perfect but this is just a start for me.
Code:
# Linear_Regression_Custom

input price = close;
input sLenght = 14;

def LRS = 6 * ( WMA(price, sLenght) -  Average(price, sLenght) ) / (sLenght - 1);


plot MiddleLR = InertiaAll(price);
def dist = HighestAll(AbsValue(MiddleLR - price));
plot UpperLR = MiddleLR + dist;
plot LowerLR = MiddleLR - dist;
def offset = Round((UpperLR - LowerLR)* .11, 3);
plot UpperLR_offset = UpperLR - offset;
plot LowerLR_offset = LowerLR + offset;

#Bullish stuff
def bullCrossLRS = LRS[1] <= LRS;
def lowRevZone = price <= LowerLR_offset within 1 bars;
plot bullEntry = lowRevZone and bullCrossLRS;
bullEntry.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullEntry.SetDefaultColor(Color.GREEN);
bullEntry.setLineWeight(3);

#Bearish Stuff
def bearCrossLRS = LRS[1] >= LRS;
def upperRevZone = price >= UpperLR_offset within 1 bars;
plot bearEntry = upperRevZone and bearCrossLRS;
bearEntry.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearEntry.SetDefaultColor(Color.RED);
bearEntry.setLineWeight(3);


#Default Look & feel
MiddleLR.SetDefaultColor(Color.YELLOW);
UpperLR.SetDefaultColor(Color.RED);
LowerLR.SetDefaultColor(Color.GREEN);
LowerLR_offset.SetDefaultColor(Color.GREEN);
LowerLR_offset.SetStyle(curve.SHORT_DASH);
UpperLR_offset.SetDefaultColor(Color.RED);
UpperLR_offset.SetStyle(curve.SHORT_DASH);
 

TOSFan8

New member
Hi all, I'm a bit new to using the LinearRegChVar study in a scanner. I've tried to figure out a way to limit the scanner to only considering the time interval of "Today", but I'm not finding an answer. Does anyone know if that's even possible? And if it is possible, would you mind giving me a clue?
 

Similar threads

Top