Jump to content
lucian_dinu

Think or Swim DATR vs ATR and %DATR label script

Recommended Posts

The Think or Swim / TOS Script /Code bellow will display a label into the volume box, showing the value of Daily ATR versus current Day ATR and % of the Daily ATR achieved in the current session / Day.    

Pictures attached for reference. 

Bellow are two versions of the script 

1. Label is GREY under 70% DATR , Turns Green over 70% of the DATR, tuns RED over 100% DATR 

2.  Label is GERY under 70% DATR , Turns Green over 70% of the DATR

 

1.st Version -------Label is GREY under 70% DATR , Turns Green over 70% of the DATR, tuns RED over 100% DATR 

# ----------------------------------------------------------
#  DATR vs Today-ATR  –  volume-pane label
#  DATR = 14-day Wilders-smoothed TrueRange from DAILY bars
#  ATS  = today’s intraday High – Low
# ----------------------------------------------------------
declare on_volume;

input dailyATRLength  = 14;
input averageType     = AverageType.WILDERS;

# ---------- Daily ATR (computed from daily bars) ----------
def dailyTR  = TrueRange(
                 high(period = AggregationPeriod.DAY),
                 close(period = AggregationPeriod.DAY),
                 low(period  = AggregationPeriod.DAY)
               );
def dailyATR = MovingAverage(averageType, dailyTR, dailyATRLength);

# ---------- Today’s session range ----------
def todayHi  = high(period = AggregationPeriod.DAY);
def todayLo  = low(period  = AggregationPeriod.DAY);
def todayATR = todayHi - todayLo;

# ---------- Percentage ----------
def pct = if dailyATR != 0 then Round((todayATR / dailyATR) * 100, 1) else 0;

# ---------- Label ----------
AddLabel(
    yes,
    "DATR " + Round(dailyATR, 2) + " vs ATR " + Round(todayATR, 2) + " (" + pct + "%)",
    if pct >= 100      then Color.GREEN
    else if pct >= 70  then Color.YELLOW
    else Color.GRAY
);

 

 

 

2.nd Version ------- Label is GERY under 70% DATR , Turns Green over 70% of the DATR

# ----------------------------------------------------------
#  DATR vs Today-ATR  –  volume-pane label
#  DATR = 14-day Wilders-smoothed TrueRange from DAILY bars
#  ATS  = today’s intraday High – Low
# ----------------------------------------------------------
declare on_volume;

input dailyATRLength  = 14;
input averageType     = AverageType.WILDERS;

# ---------- Daily ATR (computed from daily bars) ----------
def dailyTR  = TrueRange(
                 high(period = AggregationPeriod.DAY),
                 close(period = AggregationPeriod.DAY),
                 low(period  = AggregationPeriod.DAY)
               );
def dailyATR = MovingAverage(averageType, dailyTR, dailyATRLength);

# ---------- Today’s session range ----------
def todayHi  = high(period = AggregationPeriod.DAY);
def todayLo  = low(period  = AggregationPeriod.DAY);
def todayATR = todayHi - todayLo;

# ---------- Percentage ----------
def pct = if dailyATR != 0 then Round((todayATR / dailyATR) * 100, 1) else 0;

# ---------- Label ----------
AddLabel(
    yes,
    "DATR " + Round(dailyATR, 2) + " vs ATR " + Round(todayATR, 2) + " (" + pct + "%)",
    if pct >= 70      then Color.GREEN
      else Color.GRAY
);

 

 

 

image.thumb.png.7ac8ab586cf7d3bd405858fe1f8e0f5b.png

image.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.