ATR Percentile Rank Indicator for ThinkorSwim

Code:
#CM_ATR_Percentile for ThinkorSwim Version 1.0
#
#VERSION
# 2020.01.03 V1.0 @diazlaz - Initial Port
#
#LINK/CREDITS
#https://www.tradingview.com/script/D56mCdlz-CM-ATR-PercentileRank/
#https://www.tradingview.com/u/ChrisMoody/
#
#INSTRUCTION
#CM ATR PercentileRank - Great For Showing Market Bottoms.
#
#When Increased Volatility to the Downside Reaches Extreme Levels
#it’s Usually a Sign of a Market Bottom.
#
#This Indicator Takes the ATR and uses a different LookBack Period
#to calculate the Percentile Rank of ATR Which is a Great Way To
#Calculate Volatility
#

declare lower;

#INPUTS
input length = 1; #ATR Length
input length2 = 252; #no. of Bars the PercentileRank uses to Calculate % Values
input sn = no; #Show Normal Histogram? Uncheck = Histogram based on Up/Down Close
input paintBars = yes;
input showLabels = yes;

#LOGIC

#LABELS
AddLabel (showLabels, "ATR Percentile for ThinkorSwim Version 1.0", COLOR.ORANGE);

#//ATR and PercentileRank Calculations
def atr = Average(TrueRange(high, close, low), length);

def percentRankCount = fold i = 1 to length2 + 1 with count = 0
do
  if atr[0] > atr[i] then
    count + 1
  else
    count;

def percentRank = Round( percentRankCount / length2 * 100.0, 0);

def down = close < close[1];
def up = close > close[1];

#//Calculation for Showing Histogram based on Up/Down Close
def pctileRankFinal = if up then percentRank else if down then percentRank * -1 else Double.NaN;

#PLOTS
plot pATRRank = if(sn,percentRank,pctileRankFinal);
pATRRank.SetPaintingStrategy(paintingStrategy = PaintingStrategy.HISTOGRAM);
pATRRank.AssignValueColor(
if percentRank <= 70 then COLOR.GRAY else
if percentRank > 70 and percentRank < 80 then COLOR.ORANGE else
if percentRank >= 80 and percentRank <= 90 then COLOR.RED else
if percentRank >= 90 then COLOR.MAGENTA else
COLOR.DARK_GRAY
);
pATRRank.SetLineWeight(5);

#COLORBARS
AssignPriceColor(if paintbars then
if percentRank <= 70 then COLOR.GRAY else
if percentRank > 70 and percentRank < 80 then COLOR.ORANGE else
if percentRank >= 80 and percentRank <= 90 then COLOR.RED else
if percentRank >= 90 then COLOR.MAGENTA else COLOR.DARK_GRAY
else
COLOR.CURRENT
);

#END OF CM_ATR_Percentile for ThinkorSwim Version 1.0

AddLabel(yes, percentRank,
if percentRank <= 70 then COLOR.GRAY else
if percentRank > 70 and percentRank < 80 then COLOR.ORANGE else
if percentRank >= 80 and percentRank <= 90 then COLOR.RED else
if percentRank >= 90 then COLOR.MAGENTA else
COLOR.DARK_GRAY) ;
[/QUOTE]
[USER=3357]@MerryDay[/USER] Not sure why it keeps saying invalid statement once the label portion is attached.
 

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
448 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