Hello Nicholas,
This is brilliant. Many thanks. One last request Nicholas please, can you please let me know how to start the upper and lower line from 50 bars before dynamically instead of anchoring it to a fixed date and time. It needs a little change to your code to make the start point dynamic please.
Many thanks, Nicholas.
Regards,
how to start the upper and lower line from 50 bars before dynamically instead of anchoring it to a fixed date and time
That’s what the initial indicators was doing, so I don’t understand your question?
Sorry Nicholas, for the confusion, if any.
If you remember, we can not set the ALERT on the initial indicator as depicted below.
This is why, the request is how to set an ALERT in the initial indicator or the anchored one if it’s starting point is 50 bar behind dynamically.
Anyone will suffice the request please.
Regards,
//PRC_Std and Ste LinRegChannel | indicator
//Standard Deviation and Standard Error
//Linear Regression Channel
//12.03.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
defparam drawonlastbaronly=true
defparam calculateonlastbars=1000
// --- settings
// chnlper = 200, sdsr = 1, devmul = 1.62
lookback= chnlper //channel period = 50
ChannelType = sdsr //1= Standard Deviation ; 2= Standard Erro
NbDeviation = devmul //Deviation multiplier = 1
colorRed = C1
colorGreen = C2
colorBlue = C3
// --- end of settings
sumx = 0
sumy = 0
sumxy = 0
sumx2 = 0
for cmpt = lookback downto 0 do
tmpx = cmpt
tmpy = close[cmpt]
sumy = sumy+tmpy
sumx = sumx+tmpx
sumx2 = sumx2 + (tmpx*tmpx)
sumxy = sumxy + (tmpy*tmpx)
next
n = lookback+1
if (sumx2 = sumx * sumx) then // protection to avoid infinite values
b = sumxy - sumx * sumy
else
b = (n * sumxy - sumx * sumy) / (n * sumx2 - sumx * sumx)
endif
a = (sumy - b * sumx) / n
//drawsegment(barindex[lookback],a+b*lookback,barindex,a+b*0) coloured(colorRed,colorGreen,colorBlue)
//channel
if ChannelType = 1 then //Standard Deviation
dat = std[lookback]*NbDeviation
elsif ChannelType = 2 then
dat = ste[lookback]*NbDeviation
endif
drawsegment(barindex[lookback],(a+b*lookback)+dat,barindex,a+b*0+dat) coloured(colorRed,colorGreen,colorBlue)
drawsegment(barindex[lookback],(a+b*lookback)-dat,barindex,a+b*0-dat) coloured(colorRed,colorGreen,colorBlue)
return
Here is the version of the channel with dynamic lookback and with returned values for the upper and lower lines to create signals:
//PRC_Std and Ste LinRegChannel | indicator
//Standard Deviation and Standard Error
//Linear Regression Channel
//12.03.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
defparam drawonlastbaronly=true
defparam calculateonlastbars=1000
// --- settings
lookback= 200 //channel period
ChannelType = 1 //1= Standard Deviation ; 2= Standard Erro
NbDeviation = 1 //Deviation multiplier
colorRed = 255
colorGreen = 255
colorBlue = 0
// --- end of settings
sumx = 0
sumy = 0
sumxy = 0
sumx2 = 0
for cmpt = lookback downto 0 do
tmpx = cmpt
tmpy = close[cmpt]
sumy = sumy+tmpy
sumx = sumx+tmpx
sumx2 = sumx2 + (tmpx*tmpx)
sumxy = sumxy + (tmpy*tmpx)
next
n = lookback+1
if (sumx2 = sumx * sumx) then // protection to avoid infinite values
b = sumxy - sumx * sumy
else
b = (n * sumxy - sumx * sumy) / (n * sumx2 - sumx * sumx)
endif
a = (sumy - b * sumx) / n
drawsegment(barindex[lookback],a+b*lookback,barindex,a+b*0) coloured(colorRed,colorGreen,colorBlue)
//channel
if ChannelType = 1 then //Standard Deviation
dat = std[lookback]*NbDeviation
else
dat = ste[lookback]*NbDeviation
endif
drawsegment(barindex[lookback],(a+b*lookback)+dat,barindex,a+b*0+dat) coloured(colorRed,colorGreen,colorBlue)
drawsegment(barindex[lookback],(a+b*lookback)-dat,barindex,a+b*0-dat) coloured(colorRed,colorGreen,colorBlue)
startbar=barindex[lookback]
endbar=barindex
coeff = ((a+b)-(a+b*lookback))/(max(1,endbar-startbar))
return ((a+b*lookback)+dat)+(barindex-startbar)*coeff coloured(100,100,100,0) as "upper line",((a+b*lookback)-dat)+(barindex-startbar)*coeff coloured(100,100,100,0) as "lower line"
You are a GENIUS, my dear Nicholas.
Thanks a trillion for your kind, fast and reliable response.
Really appreciate your effort.
Best regards,
Hello Nicholas,
It seems the standard error channel is not working properly in Bitcoin’s monthly chart as shown in the enclosed chart.
Appreciate if it can be fixed.
Regards,
Because you are using a logarithmic scale.