Standard Deviation Scan Label Watchlist for ThinkorSwim

@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.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@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 ;
 
@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?
 
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.
 
@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.
 
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;
 
@pradeepg95 I have had the same results when i put within XX bars. I have found that if you put "within 1 bars" it will give you results. I cannot tell you why more than 1 bar yields none. Also set fullRange = No if you want to go back 90 bars
 
you have it scanning the scan within itself within 10 bars of the scan. what you are trying to do i assume is the following:

To go back within 10 bars [10] and () to segregate the defined syntax by itself

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[10]);
 
Let me try to explain it to you better.... because the study adjusts to your chart and bars since you are drawing deviation lines, one might plot different than another if ANY1 of the following settings don't BOTH match the scanner and chart study. you have to define the same length, days back to scan, and define each bar time. ALL 3 must match for both scanner and study or it will come back with different results.

In theory people tend to want to find points of support and resistance that a good majority of other people may be looking at, due to the nature of this study, this study will change depending on how far back someone's chart goes even with the same aggregation. In a sense this study is more of a quick visualization reference and in my opinion is kind of useless as a scan due the the variations of different results it yields. In other words there is no constant unless someone else uses the same EXACT settings as you are starting to find out from trying to scan against it on your chart.
 
Hi All,

Looking through the forum and don't see my question specifically addressed.

I use the standard deviation study in TOS to look for stocks trading above/below the 2nd and 3rd standard deviation. I just want to create a scanner the shows when a stock is "currently" trading above/below the 2nd and 3rd Standard Deviation so i can look for entries. I'm trying to create the scanner and just cant seem to get it to do what i want. I don't care if the stock was trading above or below during the current day but ONLY currently, so i can look for entries, so i imagine the stock would fall off the scanner when its not longer trading in this area. Also, I want this for the 1D:1M time frame. Or what ever time frame i choose. I really just need clarity on the filter section to implement this.

Thanks
 
For the scan, use the StandardDeviationChannel study and set "Close" to be "Less Than" or "Greater Than" 2 or 3 times the standard deviation of "x" period linear regression line. Then uncheck "EXT" and set the time box for "1 min". You have to calculate "x" as the number of 1m bars to be used in the length of time you want to calculate the STD.

For example, if I pull up the standard 1m chart at end of day for a stock I get two days worth of the data and the STD will calculate that data set. If I was to change the chart to a 1m 5 day chart, then the STD would calculate on 5 days worth of data, the STD lines would be completely different.

So decide on the timeframe to use (how many days), then if you want to scan on 1min results, multiply 60 times the number of hours in the period you wish to measure. I tested and it seemed to work when I used 780 for "x" (6.5 hours x 2 days X 60). Its late so I hope I got this down correctly :)
 
@agorena123 is correct, in order to scan against STD properly you need to have a defined length of the deviation you want to scan against which should match your chart that you will be using to chart it.
 
Hi, I am trying to find a scan that lets me search for stocks that have just gone above or below 1.5 standard deviation channel (say within 3 bars) on a 195 minute time period. anyone???

thanks.
 
Last edited by a moderator:
here's a simple 3x standard deviation channel watchlist column i put together – it changes colors depending on where a stock's close is. if it's above the regression line, labels signal when it's above a deviation. if it's below the regression line, labels signal when it's below another deviation. just note the timeframe you want is set at the top of the watchlist code window.

colors can be tweaked how you like. right now it signals anything above (green) or below (red) a 2nd deviation – everything else is gray.

Screen-Shot-2022-01-18-at-9-53-39-AM.png

Screen-Shot-2022-01-18-at-9-54-08-AM.png



Code:
#
# 3x standard deviation watchlist column
# @rough__sleeper
#

def price = close;
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 onedeviationUP = regression + 1 * stdDeviation;
def onedeviationDOWN = regression - 1 * stdDeviation;
def twodeviationUP = regression + 2 * stdDeviation;
def twodeviationDOWN = regression - 2 * stdDeviation;
def threedeviationUP = regression + 3 * stdDeviation;
def threedeviationDOWN = regression - 3 * stdDeviation;

AddLabel(1,
    if  close > threedeviationUP then " 3 Dev Up "
    else if close < threedeviationDOWN then " 3 Dev Dn "
    else if close > twodeviationUP then " 2 Dev Up "
    else if close < twodeviationDOWN then " 2 Dev Dn "
    else if close > onedeviationUP then " 1 Dev Up "
    else if close < onedeviationDOWN then " 1 Dev Dn "
    else if close > regression then " Reg Up "
    else if close < regression then " Reg Dn "
    else " "
,
    Color.Black
);

#AssignBackgroundColor(if close > regression then Color.LIME else if close < regression then color.PINK else Color.BLACK);
AssignBackgroundColor(if close > twodeviationUP then Color.GREEN else if close < twodeviationDOWN then color.RED else if close > regression then Color.GRAY else if close < regression then color.GRAY else Color.BLACK);
 
Last edited by a moderator:
I have search far and wide and can't find an answer. If you have a place to point me, great, if not, some help would be greatly appreciated.

I am trying to create a scanner that tells me when a stock price is at least 2 standard deviations higher or lower than normal. I want it to be on the 1 minute chart and only take data from the last days worth of market hours. Preferably with extended hours off. Anyone have a solution?

Thanks!
 
I have search far and wide and can't find an answer. If you have a place to point me, great, if not, some help would be greatly appreciated.

I am trying to create a scanner that tells me when a stock price is at least 2 standard deviations higher or lower than normal. I want it to be on the 1 minute chart and only take data from the last days worth of market hours. Preferably with extended hours off. Anyone have a solution?

Thanks!
I moved your question to this thread. Plug&play the scripts that you find here and see if it helps.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
259 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top