#APTR Percentile Rank for ThinkorSwim Version 1.0
#
#VERSION
# 2020.04.11 V1.0 @diazlaz - Initial Release
#
#
#INSTRUCTION
#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;
input length = 10;
input length2 = 100; #no. of Bars the PercentileRank uses to Calculate Rank
input averageType = AverageType.WILDERS;
input paintBars = yes;
input showLabels = yes;
#LABELS
AddLabel (showLabels, "APTR Percentile Rank for ThinkorSwim Version 1.0", COLOR.ORANGE);
#APTR
def bottom = Min(close[1], low);
def tr = TrueRange(high, close, low);
def ptr = tr / (bottom + tr / 2) * 100;
def APTR = MovingAverage(averageType, ptr, length);
#Percentile Rank Calculation
def percentRankCount = fold i = 1 to length2 + 1 with count = 0
do
if APTR[0] > APTR[i] then
count + 1
else
count;
def percentRank = Round( percentRankCount / length2 * 100.0, 0);
#PLOTS
plot pATRRank = percentRank;
pATRRank.SetLineWeight(2);
pATRRank.SetDefaultColor(GetColor(8));
plot p25 = 25;
plot p50 = 50;
plot p75 = 75;
p25.setDefaultColor(COLOR.DARK_GRAY);
p25.HideTitle();
p25.HideBubble();
p50.setDefaultColor(COLOR.DARK_GRAY);
p50.HideTitle();
p50.HideBubble();
p75.setDefaultColor(COLOR.DARK_GRAY);
p75.HideTitle();
p75.HideBubble();
#END Of APTR Percentile Rank for ThinkorSwim Version 1.0