ATR Label for ThinkorSwim

roger80k

New member
Hi Guys if anyone has DTR VS ATR indicator and can post a script for TOS would really appreciate it.

Code:
#
# Copyright 2014 Scott J. Johnson (https://scottjjohnson.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# ATRLabel
#
# Displays Average True Range over the last 40 periods and the current period
#
input ATRLength = 40;

# historical ATR
def ATRValue = Average(TrueRange(high,  close,  low),  ATRLength);
def ATRPercent = ATRValue / close * 100;

# current period range
def ATRLastBar = TrueRange(high,  close,  low);

AddLabel(yes, ATRLength + " Period ATR = $" + Round(ATRValue, 2) + " (" + Round(ATRPercent, 2) + "%), Current Period Range = $" + Round(ATRLastBar, 2) + " (" + Round(ATRLastBar / close * 100, 2) + "%)", CreateColor(153, 153, 0));
 

avaughan323

New member
VIP
This is the label code I use. If you want to plot just change def to plot.

Code:
input addBlackSpacer = yes;
AddLabel(addBlackSpacer, "  ", Color.BLACK);

input lookback = 1;
input ATR_Target = 1.50;
input pbATRLength = 1;
input Show_Labels = yes;
input Show_TargetLabels = no;
input Show_ATRvalue = yes;

input length = 5;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
AddLabel(Show_Labels, Concat("ATR  @ ", ATR[1]), Color.WHITE);

AddLabel(ATR_Target, "  *  " +ATR_Target, Color.White);
AddLabel(Yes, "=", Color.White);

def vATR =  (ATR * ATR_Target);
AddLabel(Show_ATRvalue, Concat("ATR Value @ $", vATR), Color.LIME);

#def ATR_TickValue =  (ATR * ATR_Target/tickSize());

#def ATR_Value =  (ATR_TickValue * tickValue());
#AddLabel(Show_ATRvalue, Concat("ATR Value @ $", ATR_Value), Color.LIME);

#def ATR_Price = (ATR_Value/close);
#AddLabel(Show_Labels, Concat("ATR Value:Price  @ ", aspercent(ATR_Price)), Color.WHITE);



###################################################################################
#Percentile
def vol = ATR;
input DisplayATRPercentile = yes;

input TimePeriod = 250;

def data = if !isNaN(vol) then vol else vol[-1];
def hi = highest(data, TimePeriod);
def lo = lowest(data, TimePeriod);
def Percentile = (data - lo) / (hi - lo) * 100;
def lowend = Percentile < 20;
def highend = Percentile > 80;
#####################################################################################
addlabel(DisplayATRPercentile , concat("ATR Pct Rank: ",aspercent(Percentile /100)), if lowend then color.CYAN else if highend then color.PLUM else Color.GRAY);
#####################################################################################

#Targets
AddLabel(Show_TargetLabels, "Profit Target = +" +ATR[1] * ATR_Target+ "", color.GREEN);
#AddLabel(Show_TargetLabels, " : Stop Loss =  -" +ATR * 1.0+ "", color.PINK);
#AddLabel(Show_TargetLabels, " : ATR daily = " +ATR+ "", color.GRAY);
Thank you!
 

Similar threads

Top