Standard Deviation Scan Label Watchlist for ThinkorSwim

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);
Any chance you can share the TOS scan link? I can't get it to format properly in thinkscript editor and cant figure out why.
 
Any chance you can share the TOS scan link? I can't get it to format properly in thinkscript editor and cant figure out why.

this code was for the watchlist column – are you trying to turn it into a scan? it might need some tweaking. let me know, i might be able to help out.
 
Having a hard time figuring out how to script Standard Dev breakout on the watchlist column. Need a color to light up to indicate that the price has broken out from the upper line on the Standard Dev channel.

input price = close;
input deviations = 1.0;
input fullRange = Yes;
input 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;
plot UpperLineAbove = if open("priceType" = PriceType.LAST) > UpperLine then 1 else 0;
AssignBackgroundColor (if UpperLineAbove >= 1 then Color.LIME else Color.BLACK );

This is what I have so far. Looks like the InertiaAll is giving me problems. Just wondering if there is another way to do this?
 
This is what I have so far. Looks like the InertiaAll is giving me problems. Just wondering if there is another way to do this?
The inertiaAll function is a problem when used in labels, scans, watchlist, conditional orders, etc....
When using fullrange functions (ie: InertiaAll, HighestAll, etc...), a length is not provided so the plot calculation assumes the length (fullrange) of the chart.
When you attempt to use the fullrange inertiaAll function in a label, a watchlist, or a scan there is no 'plot'. So there is no "length of the chart" to assume.

Therefore, you need to provide a length. If looking to match up to your fullrange chart results, change the length setting to equal the number of bars on your chart.

Below are three scripts: Watchlist, Scan, & Chart
FYI: inertiaAll has other problems that will lag with your results.
read more here: https://usethinkscript.com/threads/...-range-lagging-issues-due-to-tos-update.8794/

Watchlist
HY4gYdf.png

Ruby:
input price = close;
input deviations = 1.0;
input length = 21;

def regression;
def stdDeviation;
regression = InertiaAll(price, length);
stdDeviation = stdevAll(price, length);

def UpperLine = regression + deviations * stdDeviation;
def UpperLineAbove = open[1] > UpperLine ;
AddLabel(yes, " ", color.black);
AssignBackgroundColor (if UpperLineAbove >= 1 then Color.LIME else Color.BLACK );

Scan
Shared Scan Link: http://tos.mx/O7FRgly Click here for --> Easiest way to load shared links
RgKSFkD.png


Chart
h3Njq6u.png

Ruby:
input price = close;
input deviations = 1.0;
input length = 21;

def regression;
def stdDeviation;
regression = InertiaAll(price, length);
stdDeviation = stdevAll(price, length);

plot UpperLine = regression + deviations * stdDeviation;
     UpperLine.AssignValueColor( if open[1] > UpperLine then color.cyan else color.gray);


plot UpperLineAbove = if open[1] > UpperLine then UpperLine else double.NaN ;
     UpperLineAbove.SetPaintingStrategy(PaintingStrategy.ARROW_down);
     UpperLineAbove.SetDefaultColor(color.blue) ;
     UpperLineAbove.SetLineWeight(1);
 
Last edited:
How to add 2 SD data?
Not sure what you are trying to achieve.
Your post doesn't have enough information for anyone to be able to assist you.
To make sure your post gets the attention and assistance it deserves, here are a few directions to keep in mind:
  • Include a screenshot of your chart and a shared chart link. This will help others understand the context of your question and allow them to replicate the conditions that you are describing.
  • Annotate your image, highlighting the confluence that you're trying to achieve, along with a more detailed written explanation. This will help others understand your question even better and give them more specific information to work with.
If you're unsure of how to share chart links or upload screenshots to the forum, don't worry, we've included some easy-to-follow directions for you.
How to create a shared chart link:
https://usethinkscript.com/threads/how-to-share-a-chart-in-thinkorswim.14221/
How to upload screenshots to the forum:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-58714


We look forward to seeing your next post and helping you out!
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
178 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