Greetings team. I’ve been working on back testing with Nicolas’s Indicator here: https://www.prorealcode.com/prorealtime-indicators/standard-deviation-standard-error-linear-regression-channel/
I’d like to develop a screener along with another indicator in order to share with you all, however, I’m a little stuck with the conditions. Ideally this is a question directly to Nicolas. But anyone who can help, please feel free. I can do the rest of the work on my own I think.
As a visual indicator, this is amazing. But how does one detect digitally, when price (close) is above (>) the top line (+1) of the channel? I’m struggling with converting the drawn-line to a number or fixed point to use for a reference.
Ideally I want to make the top line of the channel, indicator 1 and the bottom line, indicator 2 respectively.
I think this has real potential…
I’m guessing that you want to know if the current bar is above or below the lines and not if a candle in the lookback period has been above or below the lines?
If so then a+b*0+dat is the upper line y value and a+b*0–dat is the lower line y value for the current bar.
absolutely that… Thanks, I’ll have a play round with that now and see the results. Thank you, Craig 🙂
I’m sure that I made that screener already, let me check in the forums.
I can’t find it now.. anyway, what you are looking for is if the price is exceding a linear regression + standard deviation factorized, should be coded like this:
test = high > linearregression[lookback]+std[lookback]*NbDeviation OR low < linearregression[lookback]-std[lookback]*NbDeviation
screener[test]
(not tested)
Okay guys… Thank you so far. I’ve managed to learn a bit more from what you’ve both told me and I’ve merged both comments into one screener prototype. However… the MAX units I can set for the lookback is 254, ideally I’d like this to be 300.
I’m enclosing the code below for assistance. (Please keep in mind I’m a real newcomer, but I really am interested in learning more).
// --- settings
lookback= 254 //channel period
ChannelType = 1 //1= Standard Deviation ; 2= Standard Erro
NbDeviation = 1 //Deviation multiplier
// --- 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
//channel
if ChannelType = 1 then //Standard Deviation
dat = std[lookback]*NbDeviation
else
dat = ste[lookback]*NbDeviation
endif
y = a+b*0+dat
z = a+b*0-dat
test = close > y OR close < z
screener[test]
Thanks for your help and patience, Craig 🙂
Yes 254 is the maximum lookback allowed in screeners unfortunately.
Perhaps Nicolas’s simpler version returns the same results? Otherwise that is a screener based on that indicator.
Indeed, because in realtime we don’t have to compute the affine function in order to plot a line in the past, the last point of the channel is enough.
Hi Nicolas
I know you’re constantly bombarded with questions, however, I was wondering if there’s a way to code that both values must be “above” the top line. (Even though I know the line is only a drawn on object)! I’m working on this as developing the indicator for multi-timeframe, but then also for use later in a strategy to share. (I just want it to be better before sharing.
So far I have…
Timeframe (1 hour)
test1 = high > linearregression[254]+std[254]*1 OR low < linearregression[254]-std[254]*1
Timeframe (15 Minute)
test2 = high > linearregression[254]+std[254]*1 OR low < linearregression[254]-std[254]*1
screener[test1 AND test2]
However, currently this would show when say the one hour is Above the Top line but the default or 15m is below the bottom line. I know that this is correct. But it’s not the outcome I wish to return.
I may have just answered my own question on this… If it’s not this, then any help would be received with gratitude.
Timeframe (1 hour)
test1 = high > linearregression[254]+std[254]*1
test2 = low < linearregression[254]-std[254]*1
Timeframe (15 Minute)
test3 = high > linearregression[254]+std[254]*1
test4 = low < linearregression[254]-std[254]*1
screener [(test1 AND test2) OR (test3 AND test4)]
You have indeed answered your own question 🙂 That last screener code seems correct to me!