Hi,
I have an indicator here to measure the linear regression as follow:
//Parameters :
Len = 100
percent = 0.002
once j=0
de48=DPO[Len*2](close)
if de48=de48[1] and de48[1]=de48[2] and de48[2]<>de48[3] then
flag=1
endif
n=(Len*2)-4
p=(n/2)-1
d100=DPO[n](close)
moy100=close-d100
co=(moy100-moy100[1]+(close[p])/n)*n
if flag=1 and flag[1]=0 then
test=linearregression[Len](co)
test1=linearregressionslope[Len](co)
a=test1
b=test-test1*Len
endif
if flag=0 then
reg=undefined
upperchan=undefined
lowerchan=undefined
else
j=j+1
reg=a*j+b
upperchan = reg + reg*percent
lowerchan = reg – reg*percent
endif
RETURN reg COLOURED(0,0,255) as “channel center”, upperchan COLOURED(0,255,0) as “upper channel”, lowerchan COLOURED(255,0,0) as “lower channel”
It looks like in the the attached picture.
I create a scnner to scan which stock has the positive LR as follow but it finds nothing:
//Parameters :
Len = 100
percent = 0.002
once j=0
de48=DPO[Len*2](close)
if de48=de48[1] and de48[1]=de48[2] and de48[2]<>de48[3] then
flag=1
endif
n=(Len*2)-4
p=(n/2)-1
d100=DPO[n](close)
moy100=close-d100
co=(moy100-moy100[1]+(close[p])/n)*n
if flag=1 and flag[1]=0 then
test=linearregression[Len](co)
test1=linearregressionslope[Len](co)
a=test1
b=test-test1*Len
endif
if flag=0 then
reg=undefined
upperchan=undefined
lowerchan=undefined
else
j=j+1
reg=a*j+b
upperchan = reg + reg*percent
lowerchan = reg – reg*percent
endif
c1 = reg > 1
SCREENER[c1]
What could be the problem?
REG will always be > 1.
You check whether REG is on the rise:
c1 = reg > reg[1]
or falling:
c1 = reg < reg[1]
Here is my code again. But no stock is scanned out:
//Parameters :
Len = 100
once j=0
de48=DPO[Len*2](close)
if de48=de48[1] and de48[1]=de48[2] and de48[2]<>de48[3] then
flag=1
endif
n=(Len*2)-4
p=(n/2)-1
d100=DPO[n](close)
moy100=close-d100
co=(moy100-moy100[1]+(close[p])/n)*n
if flag=1 and flag[1]=0 then
test=linearregression[Len](co)
test1=linearregressionslope[Len](co)
a=test1
b=test-test1*Len
endif
if flag=0 then
reg=undefined
else
j=j+1
reg=a*j+b
endif
c1 = reg > reg[1]
SCREENER[c1]
Maybe here something wrong?
The issue is the data history, which is limited to 256 bars (unless you have the Premium version by ProRealTime).
Both the Regression and DPO use many more periods than those you oplan to use.
Try using LEN = 20 (or maybe 50, you’ll have to make some attempts till you find the max value supported).
Many thanks.
I use Len=10, then there are about 8 stocks be scanned out. Terrible. 🙂
the smaller the Len, the more stocks can be scanned out.