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:

Schmidt42205

New member
VIP
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:

bspratt22

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

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
@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.
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
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
 

jhorton56

Member
VIP
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.
 

armeredtech

New member
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:

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
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?
 

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