# Show ATR lines just for previous close?

#### floydddd

##### Active member
so, i found the code here that you see below, plotting various ATR lines based on the daily close. i thought it'd be a simple matter for me to figure out how to show just the line based on yesterday's close (skipping all the previous days) but for some reason i just can't figure it out. could i get a lil help?

i do like the way that last line is currently plotted, outside of the close. now if only i could get it extended to the right, that'd be even better.

thanks!

Code:
``````input ATRperiod = 5;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1;
input ATRMultiplier2 = 2;
input ATRMultiplier3 = 3;
input ATRMultiplier4 = 4;

def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRperiod);

def DailyClose = close(period = ”DAY”)[1];
plot HighATR = DailyClose + ATR;
plot LowATR = DailyClose - ATR;
plot HighATR2 = DailyClose + ATR * ATRMultiplier2;
plot LowATR2 = DailyClose - ATR * ATRMultiplier2;
plot HighATR3 = DailyClose + ATR * ATRMultiplier3;
plot LowATR3 = DailyClose - ATR * ATRMultiplier3;
plot HighATR4 = DailyClose + ATR * ATRMultiplier4;
plot LowATR4 = DailyClose - ATR * ATRMultiplier4;

HighATR.SetDefaultColor(color = Color.RED);
HighATR2.SetDefaultColor(color = Color.RED);
HighATR3.SetDefaultColor(color = Color.RED);
HighATR4.SetDefaultColor(color = Color.RED);
LowATR.SetDefaultColor(color = Color.GREEN);
LowATR2.SetDefaultColor(color = Color.GREEN);
LowATR3.SetDefaultColor(color = Color.GREEN);
LowATR4.SetDefaultColor(color = Color.GREEN);

HighATR.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR4.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR4.SetPaintingStrategy(PaintingStrategy.DASHES);

AddLabel(visible = yes, text = "ATR: " + Round(ATR / close * 100, 2)  + "%", color = Color.LIGHT_GRAY);
AddLabel(visible = Yes, text = "S1: " + Round(LowATR, 2), color = Color.Green);
AddLabel(visible = Yes, text = "R1: " + Round(HighATR, 2), color = Color.Red);``````

not sure what you are asking, but if you want to show something on just the current day, add this logic to a plot formula, by using
= if istoday then ....
Python:
``````# is the current bar in the current day?
def istoday = if GetLastDay() == GetDay() then 1 else 0;``````

hmmm. not sure how to use what you posted but let me be a little clearer. in the first photo, you can see that the study currently plots the various ATR lines for every day, making for a very confusing chart. i just want it to plot the levels for the current day, the lines for which are set out to the right of that last closing price. in the second pic, i've drawn a yellow box around the only lines i'd like to see. hopefully, that makes things more understandable. can you help? thanks!

this is close, but shows yesterdays data on todays bars, not todays data to the right.
because you are using [1] and day, and how i am detecting the last day.
probably a simple fix, that i am overlooking, to get it to show as you want.

Ruby:
``````# showjustprevatr_01

def na = double.nan;
input show_lines_only_current_bar = yes;

# is the current bar in the current day?
def istoday = if GetLastDay() == GetDay() then 1 else 0;
def draw = if (show_lines_only_current_bar and istoday) then 1 else if !show_lines_only_current_bar then 1 else 0;

#addchartbubble(yes, low, draw + "\n" + istoday , color.cyan, no);

input ATRperiod = 5;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1;
input ATRMultiplier2 = 2;
input ATRMultiplier3 = 3;
input ATRMultiplier4 = 4;

def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRperiod);

def DailyClose = close(period = ”DAY”)[1];

#plot HighATR = DailyClose + ATR;
#plot LowATR = DailyClose - ATR;
#plot HighATR2 = DailyClose + ATR * ATRMultiplier2;
#plot LowATR2 = DailyClose - ATR * ATRMultiplier2;
#plot HighATR3 = DailyClose + ATR * ATRMultiplier3;
#plot LowATR3 = DailyClose - ATR * ATRMultiplier3;
#plot HighATR4 = DailyClose + ATR * ATRMultiplier4;
#plot LowATR4 = DailyClose - ATR * ATRMultiplier4;

plot HighATR = if draw then (DailyClose + ATR) else na;
plot LowATR = if draw then (DailyClose - ATR) else na;
plot HighATR2 = if draw then (DailyClose + ATR * ATRMultiplier2) else na;
plot LowATR2 = if draw then (DailyClose - ATR * ATRMultiplier2) else na;
plot HighATR3 = if draw then (DailyClose + ATR * ATRMultiplier3) else na;
plot LowATR3 = if draw then (DailyClose - ATR * ATRMultiplier3) else na;
plot HighATR4 = if draw then (DailyClose + ATR * ATRMultiplier4) else na;
plot LowATR4 = if draw then (DailyClose - ATR * ATRMultiplier4) else na;

HighATR.SetDefaultColor(color = Color.RED);
HighATR2.SetDefaultColor(color = Color.RED);
HighATR3.SetDefaultColor(color = Color.RED);
HighATR4.SetDefaultColor(color = Color.RED);
LowATR.SetDefaultColor(color = Color.GREEN);
LowATR2.SetDefaultColor(color = Color.GREEN);
LowATR3.SetDefaultColor(color = Color.GREEN);
LowATR4.SetDefaultColor(color = Color.GREEN);

HighATR.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR4.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR4.SetPaintingStrategy(PaintingStrategy.DASHES);

AddLabel(visible = yes, text = "ATR: " + Round(ATR / close * 100, 2)  + "%", color = Color.LIGHT_GRAY);
AddLabel(visible = Yes, text = "S1: " + Round(LowATR, 2), color = Color.Green);
AddLabel(visible = Yes, text = "R1: " + Round(HighATR, 2), color = Color.Red);

#``````

Last edited:
thanks a bunch. you've helped more then enuf. i'll keep plugging away at it and see if i can't figure out how to get everything right. will post if i succeed!

Ruby:
``````# if you change these 2 lines by removing the [1] ,
# i think it will show the current days lines,
# on the current day. (not shifted to the right)

# original
def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRperiod);
def DailyClose = close(period = ”DAY”)[1];

# altered
def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”), close(period = ”DAY”), low(period = ”DAY”)), ATRperiod);
def DailyClose = close(period = ”DAY”);``````

yup, i think that done did it. thanks a mil ... or however much i make using what you've done, ha ha!

okay, i think i figured out how to displace the lines to the right, thanks to a quick search at steve hahn's site. thanks again for your help!

Code:
``````# showjustprevatr_01

def na = double.nan;
input show_lines_only_current_bar = yes;

# is the current bar in the current day?
def istoday = if GetLastDay() == GetDay() then 1 else 0;
def draw = if (show_lines_only_current_bar and istoday) then 1 else if !show_lines_only_current_bar then 1 else 0;

#addchartbubble(yes, low, draw + "\n" + istoday , color.cyan, no);

input ATRperiod = 5;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1;
input ATRMultiplier2 = 1.5;
input ATRMultiplier3 = 2;

# altered
def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”), close(period = ”DAY”), low(period = ”DAY”)), ATRperiod);
def DailyClose = close(period = ”DAY”);

#def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRperiod);

#def DailyClose = close(period = ”DAY”)[1];

def HighATRa = if draw then (DailyClose + ATR) else na;
plot highatr = highatra[1];

def LowATRa = if draw then (DailyClose - ATR) else na;
plot lowatr = lowatra[1];

def HighATR2a = if draw then (DailyClose + ATR * ATRMultiplier2) else na;
plot highatr2 = highatr2a[1];

def LowATR2a = if draw then (DailyClose - ATR * ATRMultiplier2) else na;
plot lowatr2 = lowatr2a[1];

def HighATR3a = if draw then (DailyClose + ATR * ATRMultiplier3) else na;
plot highatr3 = highatr3a[1];

def LowATR3a = if draw then (DailyClose - ATR * ATRMultiplier3) else na;
plot lowatr3 = lowatr3a[1];

HighATR.SetDefaultColor(color = Color.RED);
HighATR2.SetDefaultColor(color = Color.RED);
HighATR3.SetDefaultColor(color = Color.RED);

LowATR.SetDefaultColor(color = Color.GREEN);
LowATR2.SetDefaultColor(color = Color.GREEN);
LowATR3.SetDefaultColor(color = Color.GREEN);

HighATR.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR3.SetPaintingStrategy(PaintingStrategy.DASHES);

LowATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR3.SetPaintingStrategy(PaintingStrategy.DASHES);``````

okay, i think i figured out how to displace the lines to the right, thanks to a quick search at steve hahn's site. thanks again for your help!

Code:
``````# showjustprevatr_01

def na = double.nan;
input show_lines_only_current_bar = yes;

# is the current bar in the current day?
def istoday = if GetLastDay() == GetDay() then 1 else 0;
def draw = if (show_lines_only_current_bar and istoday) then 1 else if !show_lines_only_current_bar then 1 else 0;

#addchartbubble(yes, low, draw + "\n" + istoday , color.cyan, no);

input ATRperiod = 5;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1;
input ATRMultiplier2 = 1.5;
input ATRMultiplier3 = 2;

# altered
def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”), close(period = ”DAY”), low(period = ”DAY”)), ATRperiod);
def DailyClose = close(period = ”DAY”);

#def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRperiod);

#def DailyClose = close(period = ”DAY”)[1];

def HighATRa = if draw then (DailyClose + ATR) else na;
plot highatr = highatra[1];

def LowATRa = if draw then (DailyClose - ATR) else na;
plot lowatr = lowatra[1];

def HighATR2a = if draw then (DailyClose + ATR * ATRMultiplier2) else na;
plot highatr2 = highatr2a[1];

def LowATR2a = if draw then (DailyClose - ATR * ATRMultiplier2) else na;
plot lowatr2 = lowatr2a[1];

def HighATR3a = if draw then (DailyClose + ATR * ATRMultiplier3) else na;
plot highatr3 = highatr3a[1];

def LowATR3a = if draw then (DailyClose - ATR * ATRMultiplier3) else na;
plot lowatr3 = lowatr3a[1];

HighATR.SetDefaultColor(color = Color.RED);
HighATR2.SetDefaultColor(color = Color.RED);
HighATR3.SetDefaultColor(color = Color.RED);

LowATR.SetDefaultColor(color = Color.GREEN);
LowATR2.SetDefaultColor(color = Color.GREEN);
LowATR3.SetDefaultColor(color = Color.GREEN);

HighATR.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR3.SetPaintingStrategy(PaintingStrategy.DASHES);

LowATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR3.SetPaintingStrategy(PaintingStrategy.DASHES);``````

Nice work all! If you still also want to extend those lines to the right side, try this:
Code:
``````# showjustprevatr_01

def na = double.nan;
input show_lines_only_current_bar = yes;

# is the current bar in the current day?
def istoday = if GetLastDay() == GetDay() then 1 else 0;
def draw = if (show_lines_only_current_bar and istoday) then 1 else if !show_lines_only_current_bar then 1 else 0;

#addchartbubble(yes, low, draw + "\n" + istoday , color.cyan, no);

input ATRperiod = 5;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1;
input ATRMultiplier2 = 1.5;
input ATRMultiplier3 = 2;

# altered
def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”), close(period = ”DAY”), low(period = ”DAY”)), ATRperiod);
def DailyClose = close(period = ”DAY”);

#def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRperiod);

#def DailyClose = close(period = ”DAY”)[1];

def HighATRa = if isnan(close) then HighATRa[1] else if draw then (DailyClose + ATR) else na;
plot highatr = highatra[1];

def LowATRa = if isnan(close) then LowATRa[1] else if draw then (DailyClose - ATR) else na;
plot lowatr = lowatra[1];

def HighATR2a = if isnan(close) then HighATR2a[1] else if draw then (DailyClose + ATR * ATRMultiplier2) else na;
plot highatr2 = highatr2a[1];

def LowATR2a = if isnan(close) then LowATR2a[1] else if draw then (DailyClose - ATR * ATRMultiplier2) else na;
plot lowatr2 = lowatr2a[1];

def HighATR3a = if isnan(close) then HighATR3a[1] else if draw then (DailyClose + ATR * ATRMultiplier3) else na;
plot highatr3 = highatr3a[1];

def LowATR3a = if isnan(close) then LowATR3a[1] else if draw then (DailyClose - ATR * ATRMultiplier3) else na;
plot lowatr3 = lowatr3a[1];

HighATR.SetDefaultColor(color = Color.RED);
HighATR2.SetDefaultColor(color = Color.RED);
HighATR3.SetDefaultColor(color = Color.RED);

LowATR.SetDefaultColor(color = Color.GREEN);
LowATR2.SetDefaultColor(color = Color.GREEN);
LowATR3.SetDefaultColor(color = Color.GREEN);

HighATR.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR3.SetPaintingStrategy(PaintingStrategy.DASHES);

LowATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR3.SetPaintingStrategy(PaintingStrategy.DASHES);``````

sleepyz: oh my that's beautiful. love them long lines. thanks a bunch!

please post the final chart pic to show the finished product thanks

87k+ Posts
261 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?