ATR with Standard Deviation and Average for ThinkorSwim

skynetgen

Well-known member
ITs quite revealing about certain market behavior.

thinkScript Code

Code:
#skynetgen
#atr with stdev

declare lower;

input length = 14;
input averageType = AverageType.WILDERS;
input avglength=20;

 
def tr = TrueRange(high, close, low);


plot ATR = MovingAverage(averageType, tr, length);
ATR.SetDefaultColor(GetColor(8));
plot avg=expAverage(atr,avglength);
addcloud(atr,avg,color.green,color.red);

#stdev code. put in relvalue which you want measure
input RelDevLength=20;
input numDev = 1.0;
input ExtraDev = 2.3;
input MegaDev=4;
input MinDev=-1.3;
def relvalue=tr;
def rawRelDev = (relvalue - Average(relvalue , RelDevLength)) / StDev(relvalue, RelDevLength);
def base=lowest(relvalue,20); def cutoff=relvalue;
plot relstdev=if rawreldev+base>=cutoff then cutoff else base+rawreldev;

relstdev.setpaintingStrategy(paintingStrategy.SQUARED_HISTOGRAM);
relstdev.assignValueColor(
    if rawreldev>=MegaDev then color.cyan
    else if rawreldev>ExtraDev then color.green
    else if rawreldev>NumDev then color.dark_green
    else if RawRelDev<MinDev then  color.DARK_GRAY
    else color.current
    );

https://tos.mx/O9llhgT
 
Last edited by a moderator:

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

Having trouble scanning for Cyan bars, looking to add the following to the code " cyan. plot go=rawRelDev >= MegaDev;" so that I can scan for "Go to be true" but keep coming up with errors. Does anybody have any ideas on how to make this work? Thank you for everyone's help, this site is very useful!!!
 
Last edited:
ITs quite revealing about certain market behavior.

thinkScript Code
Code:
#skynetgen
#atr with stdev

declare lower;

input length = 14;
input averageType = AverageType.WILDERS;
input avglength=20;

 
def tr = TrueRange(high, close, low);


plot ATR = MovingAverage(averageType, tr, length);
ATR.SetDefaultColor(GetColor(8));
plot avg=expAverage(atr,avglength);
addcloud(atr,avg,color.green,color.red);

#stdev code. put in relvalue which you want measure
input RelDevLength=20;
input numDev = 1.0;
input ExtraDev = 2.3;
input MegaDev=4;
input MinDev=-1.3;
def relvalue=tr;
def rawRelDev = (relvalue - Average(relvalue , RelDevLength)) / StDev(relvalue, RelDevLength);
def base=lowest(relvalue,20); def cutoff=relvalue;
plot relstdev=if rawreldev+base>=cutoff then cutoff else base+rawreldev;

relstdev.setpaintingStrategy(paintingStrategy.SQUARED_HISTOGRAM);
relstdev.assignValueColor(
    if rawreldev>=MegaDev then color.cyan
    else if rawreldev>ExtraDev then color.green
    else if rawreldev>NumDev then color.dark_green
    else if RawRelDev<MinDev then  color.DARK_GRAY
    else color.current
    );

https://tos.mx/O9llhgT
@skynetgen @MerryDay - can you please explain how you use your indicator? What the different colored bars represent and what you look for in a setup?
 
Last edited by a moderator:
@skynetgen @MerryDay - can you please explain how you use your indicator? What the different colored bars represent and what you look for in a setup?
Did you know that clicking on a member's avatar will allow you to see when a member was last seen on the uTS forum? @skynetgen has not been seen in a while. :(

This type of indicator is popular in its use as support & resistance.
 
the code not working, looking to add this code plot go=rawRelDev >= MegaDev; it keep coming up with error, how did you figure it out do you have any ideas on how to make it work? Thanks for the help.
Are you saying "coming up with error" when you cut and paste the code?
There are no errors. Try again to cut & paste. You should have an image that looks like this:
ATigzfq.png
 
Where can I go to find out what these inputs mean?

input RelDevLength=20;
input numDev = 1.0;
input ExtraDev = 2.3;
input MegaDev=4;
input MinDev=-1.3;

Otherwise, this study makes absolutely no sense to me.
 
I only use this during market hours so it isn't built to be correct in pre- and post-market
Ruby:
input length = 13;
input averageType = AverageType.WILDERS;
input numDev = 1;
input numDev2 = 2;
input Period = AggregationPeriod.DAY;
plot closeedge = close(period = Period)[1];
def timeopen = SecondsFromTime(0930);
def timeclose = SecondstillTime(1600);

def markethours = if timeopen >= 0 and timeclose > 0 then 1 else 0;
def marketopen = if timeopen == 0 then 1 else 0;

def date = GetYYYYMMDD();
def datecount = CountTradingDays( 20000101, date);

rec dayhigh = if (markethours == 1) then if (marketopen == 1) then high else if high > dayhigh[1] then high else dayhigh[1] else dayhigh[1];

rec daylow = if (markethours == 1) then if (marketopen == 1) then low else if low < daylow[1] then low else daylow[1] else daylow[1];




def ATR = MovingAverage(averageType, TrueRange(high(period = Period), close(period = Period), low(period = Period)), length);

def StdDev = StDev(TrueRange(high(period = Period), close(period = Period), low(period = Period)), length);

def midhigh = if dayhigh - daylow > Max(AbsValue(dayhigh - close(period = Period)[1]), AbsValue( daylow - close(period = Period)[1])) then (daylow + atr) else (if dayhigh < close(period = Period)[1] then (daylow + atr) else close(period = Period)[1] + ATR);


def UpperBandhigh = midhigh + numDev * StdDev;
def LowerBandhigh = midhigh - numDev * StdDev;


def UpperBandhigh2 = midhigh + numDev2 * StdDev;
def LowerBandhigh2 = midhigh - numDev2 * StdDev;



def midlow = if (dayhigh - daylow) > Max(AbsValue(dayhigh - close(period = Period)[1]), AbsValue( daylow - close(period = Period)[1])) then (dayhigh - ATR) else (if daylow > close(period = Period)[1] then (dayhigh - ATR) else close(period = Period)[1] - ATR);

def UpperBandlow = midlow + numDev * StdDev;
def LowerBandlow = midlow - numDev * StdDev;


def UpperBandlow2 = midlow + numDev2 * StdDev;
def LowerBandlow2 = midlow - numDev2 * StdDev;

plot atrhigh = midhigh;
plot atrhighup = UpperBandhigh;
plot atrhighdown = LowerBandhigh;
plot atrhighup2 = UpperBandhigh2;
plot atrhighdown2 = LowerBandhigh2;

plot atrlow = midlow;
plot atrlowup = UpperBandlow;
plot atrlowdown = LowerBandlow;
plot atrlowup2 = UpperBandlow2;
plot atrlowdown2 = LowerBandlow2;
 
Last edited by a moderator:
Where can I go to find out what these inputs mean?

input RelDevLength=20;
input numDev = 1.0;
input ExtraDev = 2.3;
input MegaDev=4;
input MinDev=-1.3;

Otherwise, this study makes absolutely no sense to me.
The OP has not been seen in a while so is not available to explain the thinking behind the original post.
@armeredtech's version perhaps is easier to understand?
 
@brook0010
@MerryDay
Just wondering how to add this as a scanner. I have this stored as a Study "Cm_RelStdDev". How do I scan for that plot?

This is definitely not what you specified: plot go=rawRelDev >= MegaDev;
1708876726066.png


But if I go to the Thinkscript editor to write, it's also invalid.
1708876818777.png

"cyan." this should be erased

You should only have plot go=rawRelDev >= MegaDev;

Then you should be fine.
 
@brook0010
@MerryDay
Just wondering how to add this as a scanner. I have this stored as a Study "Cm_RelStdDev". How do I scan for that plot?

This is definitely not what you specified: plot go=rawRelDev >= MegaDev;
View attachment 21161

But if I go to the Thinkscript editor to write, it's also invalid.
View attachment 21162

You got all these right:
1. choose your study
2. choose go as your plot
3. is greater than or equal to for your middle column

Change your right-hand column from MegaDev to:
choose 4 as value

Your attempt got an error because MegaDev is not a selectable field.
But you know from your settings that MegaDev == 4
So just put 4 in as your value.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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