DTR vs ATR Indicator for ThinkorSwim

C

chada456

New member
I was looking at the original thread for this script and they said, they were having some issue with values. Did you figure it out?
It looks great to me. An example of this is SFIX from yesterday. It shows a DTR of $5.26.. That's accurate as the low from that day was 18.84 and the high was 24.10 (24.10 - 18.84 = 5.26) The percentage it outputs (which is what i would love to get in a scan) is 319% above it's ATR which is also accurate. Hope that helps.
 
C

chada456

New member
If anyone's interested. I found out how to scan for the percentage. It was quite easy. All the praise goes to the original creator of this script but here's the code to be able to scan by %

Code:
# Custom ATR Plot by 7of9 for BRT
# edited 3/20/19
input AtrAvgLength = 14;

def ATR = WildersAverage(TrueRange(high(period = aggregationPeriod.DAY), close(period = aggregationPeriod.DAY), low(period = aggregationPeriod.DAY)), AtrAvgLength);

def TodayHigh = Highest(high(period = aggregationPeriod.DAY), 1);
def TodayLow = Lowest(low(period = aggregationPeriod.DAY), 1);

def DTR = TodayHigh - TodayLow;

plot DTRpct = Round((DTR / ATR) * 100, 0);
 
V

VicD

Member
Great script. Can you tell me how I would set it to calculate the first 5, 15, 0r 30 minutes of open as part of ATR? So the opening range as percent of ATR? Tried hacking it together with an OTR scrips and getting 0's

Code:
# ------ START CODE

input ATRPeriod = 20; #Hint ATRPeriod: The ATR period for previous days, default 14.

def period = AggregationPeriod.DAY;
def ATR = MovingAverage(AverageType.WILDERS, TrueRange(high(period = period), close(period = period), low(period = period)), ATRperiod);
def showATralways = yes;



# inputs
input orStartTime = 0930;
input orEndTime = 1000;
input periodOTR = aggregationPeriod.THIRTY_MIN;
input showOnlyToday = yes;
input showCloud = yes;


# constants
def na = double.nan;
def hi = high(period = periodOTR);
def lo = low(period = periodOTR);
defineGlobalColor("Cloud", color.gray);

# opening range time logic
def isOr = secondstilltime(orEndTime) > 0
    and secondsfromtime(orStartTime) >= 0;
def today = (!showOnlyToday or getday() == getlastday())
    and secondsfromtime(orStartTime) >= 0 and !isNAN(close);

# opening range levels logic
rec orhi =
    if orhi[1] == 0
        or !isOr[1]
        and isOr
    then hi
    else if isOr
        and hi > orhi[1]
    then hi
    else orhi[1];

rec orlo =
    if orlo[1] == 0
        or !isOr[1]
        and isOr
    then lo
    else if isOr
        and lo < orlo[1]
    then lo
    else orlo[1];

def OTRrng = Round((hi - lo),2);
AddLabel(showATRalways, "DayRng: " + OTRrng + " vs. ATR: " + Round(ATR,2) + " (" + Round(((OTRrng/ATR)*100),2) +"%)" , color.green);

# ------- END CODE
 
Last edited by a moderator:
C

convertiblejay

New member
@Shinthus does the percentage stop at 100% or can it go past it?
 
V

VicD

Member
Ok. So this is a messy code but it does what it needs to do. Please feel free to edit. This script is the Daily Opening Range of ATR. Those of you that are momentum traders will see the reason for it.

Code:
# ------ START CODE

input ATRPeriod = 20; #Hint ATRPeriod: The ATR period for previous days, default 14.

def period = AggregationPeriod.DAY;
def ATR = MovingAverage(AverageType.WILDERS, TrueRange(high(period = period), close(period = period), low(period = period)), ATRperiod);
def showATralways = yes;



# inputs
input orStartTime = 0930;
input orEndTime = 1000;
input periodOTR = aggregationPeriod.THIRTY_MIN;
input showOnlyToday = yes;
input showCloud = yes;


# constants
def na = double.nan;
def hi = high(period = periodOTR);
def lo = low(period = periodOTR);


# opening range time logic
def isOr = secondstilltime(orEndTime) > 0
    and secondsfromtime(orStartTime) >= 0;
def today = (!showOnlyToday or getday() == getlastday())
    and secondsfromtime(orStartTime) >= 0 and !isNAN(close);


# opening range levels logic
rec OR100 =
    if OR100[1] == 0
        or !isOr[1]
        and isOr
    then hi
    else if isOr
        and hi > OR100[1]
    then hi
    else OR100[1];

rec OR0 =
    if OR0[1] == 0
        or !isOr[1]
        and isOr
    then lo
    else if isOr
        and lo < OR0[1]
    then lo
    else OR0[1];


def range = OR100 - OR0;



def OTRrng = range;
AddLabel(showATRalways, "DORng: " + OTRrng + " vs. ATR: " + Round(ATR,2) + " (" + Round(((OTRrng/ATR)*100),2) +"%)" , color.green);




# ------- END CODE
 
Last edited by a moderator:

Top