Standard Deviation Scanner for ThinkorSwim

wimberly398

New member
I am trying to build a very simple scanner using the standard deviation channel …….. what I want it to do is when it crosses the 2nd deviation line "lower line " on a daily chart I want it to pop up on the scanner …I want stocks who crossed that day I run the scanner and who is still under the lower line on the deviation channel lately iv been getting who crossed few months ago in which im not interested in any help yall can give me to point me in the direction would be greatly appreciated
 

XeoNoX

Well-known member
VIP
setup the custom study as in the picture below and use it to scan:

v4YK515.png
 
I am looking for a way to use the TOS scanner to return stocks under the following criteria.

Stocks that are CURRENTLY under the 2.0 SD Channel
Stocks that are CURRENTLY over the 2.0 SD Channel
Stocks with average volume or better

Can anyone help me set up my scanner to return these stocks? On this I am not looking for RelativeVolumeStDev, rather the StandardDeviationChannel.

Thank you for your help!
 

gogoisgone

New member
VIP
Hello All,

I have seen a few posts on Standard Deviations but nothing conclusive. I am looking for help to build a watchlist with alerts around standard deviations.

I have a watchlist of 200 tickers that I trade normally. I dont trade all of them but watch them on a regular basis.

I am on a Today/1 Minute chart for most of these and am looking to scalp them.

I would like to have two things
1) a Watchlist that would have the following columns
Ticker/Last//%change/Volume which are standard. Now for the custom columns,
Ydays Low, Todays Low, 1STD-LOW/2-STD-LOW, 1-STD-HIGH/2-STD-HIGH, ORB-HIGH, ORB-LOW.

2) An alert when any of the tickers on the watchlist reach 2-STD-LOW OR 2-STD-HIGH.

Wondering if one could guide me in here.

Thanks in advance.
 

BenTen

Administrative
Staff member
Staff
VIP
It looks like you want more than just a watchlist column for the standard deviation indicator. For things like ORB (opening range breakout) we already posted it here. If you use the Search feature on the forum, you should also find other watchlist columns related to your request.
 

XeoNoX

Well-known member
VIP
ProfessorAR15, whoops your right, i messed up, all you have to do is change RetlativeVolStDev to StandardDeviationChannel under the "study"

Here is the correct below for what you asked, please not that it will catch crossings, personally i prefer to use the is less than or equal to feature incase there are "jumps" "gaps" in price movement that will trick the scanner. just my personal opinion based of prior experiences with "crossing" on tos

LrQXpqa.png



Gogoisgone, know one knows what hi-1-std is or what study you are referring to.
 

gogoisgone

New member
VIP
I currently watch Linear Regression Line and, Standard Deviation lines for 1 and 2. Each Standard Deviation has a high and low. that is what meant when I say hi-1-std... 1 standard deviation high value. Hope this helps @XeoNoX
 

XeoNoX

Well-known member
VIP
without a screenshot or very clear expination, know one can understand what you are looking at or trying to do or explain. I see quite a few linear regression studies in TOS, you have to be more specific as you can and pictures help alot, or else know one else knows what you are talking about .
 

XeoNoX

Well-known member
VIP
you have to be specific, thats "StandardDevChannel". here is the scan you requested. You can change the words "is greater than or equal to" with anything in the box above that i had listed here to meet your needs.

VlW4PnF.png


Code:
def price = close;
def deviations = 2.0;
def fullRange = Yes;
def length = 21;

def regression;
def stdDeviation;
if (fullRange) {
    regression = InertiaAll(price);
    stdDeviation = stdevAll(price);
} else {
    regression = InertiaAll(price, length);
    stdDeviation = stdevAll(price, length);
}

def UpperLine = regression + deviations * stdDeviation;
def MiddleLine = regression;
def LowerLine = regression - deviations * stdDeviation;

plot scan = close is greater than or equal to lowerline;
 

HighBredCloud

Well-known member
VIP
@XeoNoX I was looking for a scan like similar to this...What would need to be changed to scan for stocks that pull closer to the middle line of the standard deviation as indicated in post #12 picture (the blue line.)

Is it this? or do I need to change the part "close is greater than or equal to" to "above" or "below" ?

plot scan = close is greater than or equal to middle line;

I am looking for a BULLISH pullback...and a BEARISH pullback to the middle line...Thanks.
 

XeoNoX

Well-known member
VIP
@HighBredCloud
here goes your scan as requested. It will scan for tickers that are WITHIN X% of the middle line deviation.

Code:
#Price is within X% max of Middle Line StandardDevChannel StandardDevationChannel
## By XeoNoX via https://usethinkscript.com
#### INSTRUCTIONS: Change percentvalue to the desired % in decimal format
###  Example .02 is 2%  and .025 is 2.5%

def percentvalue = .03;

def price = close;
def deviations = 2.0;
def fullRange = Yes;
def length = 21;
def regression;
def stdDeviation;
if (fullRange) {
    regression = InertiaAll(price);
    stdDeviation = stdevAll(price);
} else {
    regression = InertiaAll(price, length);
    stdDeviation = stdevAll(price, length);
}

def UpperLine = regression + deviations * stdDeviation;
def MiddleLine = regression;
def LowerLine = regression - deviations * stdDeviation;


def s = MiddleLine*percentvalue;
def scan = absvalue(close - MiddleLine) is less than or equal to s;

plot study = scan ;
 

HighBredCloud

Well-known member
VIP
@XeoNoX Thank YOU so much...I will check this out...away from the computer at the moment...Out of curiosity does this scan within X amount of bars or just when the candles sticks are close to the middle line? And if the scan...scans for candles that are close to the middle line than what is considered close to the middle line...? Just want to be sure that the results generated by the scanner still leave room to make a profit and not just show stocks that already made their move...

BTW...since this scan is intended to scan for stocks close to the middle line...I am assuming that this scan is for both Bullish/Bearish?

Thanks again...I am sure for anyone who uses Standard Deviation will find this scan very useful.

EDIT: I just saw that you'd need to adjust the % value away from the middle line...Do you think that scanning for stock that cross ABOVE or BELOW the middle line would net better results as oppose to the % close to the middle line?
 

XeoNoX

Well-known member
VIP
code from post #15 plots the closing price (last price bar or line) is near/close to the middle line. The lower the percentage number the closer to the middle line, the higher the number the farther from the middle line.

-----------------------------------------------------------

if you want above or below the middle line you can use the code from post #13 of this thread and just change the final line to

Code:
plot scan = close is greater than or equal to MiddleLine;
or
Code:
plot scan = close is less than or equal to MiddleLine;


i cant tell you what has better results, i dont know what your strategy or use of this is, that is completely your call and how you incorporate it into your trading strategy. Good luck.
 

HighBredCloud

Well-known member
VIP
@XeoNoX Thanks...I will try both scanners out to see what get better results. As far as how I would use these scanners. For instance IF I scan within the % Gainers Public category for LONG results...I am assuming that when the candle stick crosses below the Standard Deviation line it may comeback to the UP side once the candle stick crosses ABOVE the Middle Standard Deviation Line again because such scanner result was scanned in % Gainers...Unless it's a total reversal a cross BELOW the Middle Standard Deviation Line would indicate a pullback most likely. And vice versa for SHORTS when scanned in % Losers...any time the candlestick would cross ABOVE the Middle Standard Deviation line I would wait for the pull back down to indicate a further downtrend.

This is something that I need to play with to see what timeframe works best with this type of a scanner as I don't know what type of a delay there would be before getting alerted. Some scanners that I have used in the past were coded to reflect immediate change when the criteria was met for that specific timeframe. Other type of scanners produced results based on X amount of bars of the criteria being met.

Thank you again for taking your time and doing the scanners...I will see how they perform and will respond to this thread once I have some data that I can share with others. Trading based on the Standard Deviation can be successful if you can find the right stock to trade...Been looking for such a scanner for a while now that can find such stocks...hopefully this is it.
 

Trentide

New member
Hey there, thanks in advance for checking out my post! I’m having an issue creating a scan using the standard deviation channel indicator that is consistent. Half the time, the scan chooses stocks that don’t fit the criteria. i’m not doing anything custom or crazy just trying to find stocks where the close is less than the standard deviation channels lower line (2.0 deviations). Basically, “ close is less than StandardDevChannel().”LowerLine” “ . In my case, I’m using the 10 minute aggregation. However, I haven’t had much luck really in any aggregation. If it’s my error, I’d sure like to figure out what I did wrong. If it’s thinkorswim, I guess I could just move on.

thanks so much!

OK, here’s an update. I figure it out something here. The scanner only works reliably for the 5 day:10 minute chart. If I choose 1 Day: 10 minute chart, it’s way off. The 10 day: 10 minute chart is close. The 20 day: 10 minute chart is also way off. What’s going on here? Why would the number of days affect the way it’s displayed? I understand that if I was changing from one minute, to 5 minute, to 10 minute increments, etc. that would change the way it’s displayed. But not the amount of days previous to the day I’m looking at. Did I change a setting somewhere?
 

Baller2356

New member
How do we plot a fixed standard deviations like 2 standard deviations on a time frame without it moving after each completed bar? I need help with the study and the scanner for it.
 

rad14733

Well-known member
VIP
How do we plot a fixed standard deviations like 2 standard deviations on a time frame without it moving after each completed bar? I need help with the study and the scanner for it.
Now, they wouldn't be standard deviations if we ignored the fact that they change value after every bar closes, would they...??? They would just be random lines that look like what we want to see... If that is the case, just plot a price line where you want it...
 

XeoNoX

Well-known member
VIP
the time aggregation must also match both the scanner and the charts you are viewing as TOS's charts will adjust to the aggregation you are using. example.... 5 minute 10 day will show different from 5 minute 1 day for this particular built in TOS study.
 

pradeepg95

New member
Why this scan is not showing any results?

Code:
def price = close;
def deviations = 2;
def fullRange = Yes;
def length = 90;

def regression;
def stdDeviation;
if (fullRange) {
    regression = InertiaAll(price);
    stdDeviation = stdevAll(price);
} else {
    regression = InertiaAll(price, length);
    stdDeviation = stdevAll(price, length);
}

def UpperLine = regression + deviations * stdDeviation;
def MiddleLine = regression;
def LowerLine = regression - deviations * stdDeviation;

plot scan = close is less than or equal to lowerline within 10 bars;
 

Similar threads

Top