@diazlaz was kind enough to help me port this version of ATR Percentile Rank from TradingView over to ThinkorSwim. I thought it was interesting.
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
Be Careful Of Using w/ Market Tops. Not As Reliable.
***Ability to Control ATR Period and set PercentileRank to Different Lookback Period
***Ability to Plot Histogram Just Showing Percentiles or Histogram Based on Up/Down Close
Fuchsia Lines = Greater Than 90th Percentile of Volatility based on ATR and LookBack Period.
Red Lines = Warning — 80-90th Percentile
Orange Lines = 70-80th Percentile
For this ToS version:
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
Be Careful Of Using w/ Market Tops. Not As Reliable.
***Ability to Control ATR Period and set PercentileRank to Different Lookback Period
***Ability to Plot Histogram Just Showing Percentiles or Histogram Based on Up/Down Close
Fuchsia Lines = Greater Than 90th Percentile of Volatility based on ATR and LookBack Period.
Red Lines = Warning — 80-90th Percentile
Orange Lines = 70-80th Percentile
For this ToS version:
- Magenta = Greater than 90th Percentile
- Orange = 70-80th
- Red = 80-90
thinkScript Code
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 = 5; #ATR Length
input length2 = 50; #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
Last edited by a moderator: