Scan using Standard Deviation error channel


Category:
0
0

Hello,

Would it be possible to scan using StandardErrorChannel(code below)? I am trying to scan if price(close) just crossed above the plot LowerBand on 5 min time frame?

input price = close;
input standardErrors = 2;
input fullRange = Yes;
input length = 21;

def regression;
def stdError;
if (fullRange) {
regression = InertiaAll(price);
stdError = sterrAll(price);
} else {
regression = InertiaAll(price, length);
stdError = sterrAll(price, length);
}

plot UpperBand = regression + standardErrors * stdError;
plot MiddleBand = regression;
plot LowerBand = regression – standardErrors * stdError;

Thanks in advance!

MD

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on June 1, 2019 4:53 pm
755 views
0
Private answer

Similar requests have already been posted here and the solution requires a clear understanding of how the historical chart data differs between the scan engine and what you see on the charts.

The Screenshots:

I have included a couple screenshots to help explain things. First is the chart settings. If you apply this study to a chart and do not change anything you get default settings. Which means the "full range" input is set to 'yes'. This causes the channels to be computed using the entire viewable area of the chart. This default setting is NOT compatible with building a scan. Why?

Notice the three charts on the second screenshot. Comments are included to explain the differences between each. Notice the huge difference for the values and plots of the channel on each chart.

A Couple of Lessons:

So the first lesson is this: The "full range" setting for this indicator MUST BE SET TO 'no'. This means BOTH the chart and the Scan must be set to "full range" == 'no'. Otherwise you will never get the scan to produce results you can see on the charts.

The next bit of information you need to understand is how much historical data the scan engine uses. When I use the term 'historical data", consider this equivalent to the viewable area of the chart. For those details, read the section at the bottom of this webpage under the heading: Data Limitations

http://tlc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker/studyfilters.html

Application:

So for the 5 min time frame we find that we only have 15 days (that's calendar days). Which roughly works out to 11 trading days. When we set the "full range" input to 'no' we need to make sure the "length" input does not exceed 11 trading days worth of whatever intraday time frame you have selected.

For example at the 30 min time frame we have 13 bars per day (regular session hours). We take 13 times 11 to compute the maximum value we can use for the "length" input when applying the 30 min time frame. That figure is 143. If you exceed this, the channels cannot be computed by the scan engine and this will produce results that cannot be replicated on the charts.

And you thought the code part of this question was the real challenge. Bet you didn't have a clue you had to learn all this new stuff before the scan could be put to use.

But Wait, There's More:

Oh, and there is one more thing. Your chart must be set to NOT start aggregation at market open. That is the third and final screenshot. The scan engine uses data that has this setting 'unchecked'. However your charts use a default value of 'checked'. So check your chart settings before posting a question asking why the results still don't match.

The Code:

Now for the code. Guess what? It only requires one additional line of code:

plot scan = close[1] < LowerBand[1] and close > LowerBand;

That's it. Oh, we do need to turn off the other plots in the study. Scans will only permit one plot. I do this by simply changing the bands from 'plot' to 'def'. And we also need to change the "full range" setting to a default value of 'no'. (that's line 3 of the code below). Be sure to adjust the "length" input to whatever suits your preferences.

input price = close;
input standardErrors = 2;
input fullRange = No;
input length = 21;
def regression;
def stdError;
if (fullRange) {
regression = InertiaAll(price);
stdError = sterrAll(price);
} else {
regression = InertiaAll(price, length);
stdError = sterrAll(price, length);
}
def UpperBand = regression + standardErrors * stdError;
def MiddleBand = regression;
def LowerBand = regression – standardErrors * stdError;
#---------- scan for when price crosses back above the lower band
plot scan = close[1] < LowerBand[1] and close > LowerBand;

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on June 2, 2019 8:55 am
0
Hi Pete, When I run the scan I get the error "Error: Length value must be greater than 2". I have changed all the settings that you suggested. I wanted to attach my chart and scan settings but couldn't do it thru comment section. Thank you!
( at June 6, 2019 3:02 pm)
0
The error appears when you "run" the scan? Or when you add the code to the study filter editor? I don't get any errors at all.
( at June 6, 2019 8:34 pm)
0
I get that error when I run the scan. I didn't get any error when I added the code to study filter.
( at June 7, 2019 10:52 am)
0
The only way I can get that error to come up is to change the input named "Length" from 21 to 1. If you copy and paste the code as is and do not make any changes it should work just fine. Why would you set the length input to 1?
( at June 7, 2019 1:19 pm)
0
I didn't change any code and it has the default length of "21". I still get the same error.
( at June 7, 2019 5:02 pm)
0
Ok, so how many time frames have you tried to use? I tested several and only found this error reported on the 1 min time frame. Per chance are you using the 1 min time frame? Have you tried others? Which time frames are causing this error?
( at June 8, 2019 11:03 am)
0
I used only 5 min and 30 min time frame. I haven't' used with 1 min time frame. It's causing error for all time frames.
( at June 18, 2019 3:17 pm)
0

Well I don’t have any solution for you. Works on mine except for that one time frame. There is nothing at all wrong with the code and nothing I can suggest to try differently.

( at June 18, 2019 5:57 pm)