# Rounding ATR levels to the nearest quarter FUTURES help

#### grapetux

##### Member
Hi there, I'm attempting to plot the below ATR levels but have the values round to the nearest quarter point to align nicely with buy/sell orders for trading /MES
Here's the code Im using for the ATR levels:

##ATR LEVELS STUDY###
input aggregationPeriod = AggregationPeriod.day;
input showOnlyLastPeriod = yes;

def prevPrice = open(period = aggregationPeriod)[-1];
def price = open(period = aggregationPeriod);
plot monthlyOpen = if showOnlyLastPeriod and !IsNaN(prevPrice) then Double.NaN else price;
monthlyOpen.setDefaultColor(createcolor(145,120,0));
monthlyOpen.setLineWeight(3);

def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def dayrange = (high - low);

def r1 = dayrange[1];
def r2 = dayrange[2];
def r3 = dayrange[3];
def r4 = dayrange[4];
def r5 = dayrange[5];
def r6 = dayrange[6];
def r7 = dayrange[7];
def r8 = dayrange[8];
def r9 = dayrange[9];
def r10 = dayrange[10];

def adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10;
def adr_5 = (r1 + r2 + r3 + r4 + r5) / 5;

def hl1 = (open + (adr_10 / 2));
def ll1 = (open - (adr_10 / 2));

def gg= hl1-open;

##lines##

#targets##
addlabel(1," " + "1xx " +roundup(s) + " // " + "2xx " +roundup(e) + " // "+ "4xx " +roundup(q) + " ", color.gray);
addlabel(1," " + "1conSL: " +s*5+ " // " + "2conSL: " +roundup(s*10) + " // " + "5conSL: " +roundup(s*25)+ " // " + "10conSL: " +s*50 + " " , color.gray);

#Eighths ATR
plot e1= open+e;
e1.setDefaultColor(createcolor(95,95,95));
e1.setStyle(curve.short_dash);
plot e3= open+e*3;
e3.setDefaultColor(createcolor(95,95,95));
e3.setStyle(curve.short_dash);
plot e5= open+e*5;
e5.setDefaultColor(createcolor(95,95,95));
e5.setStyle(curve.short_dash);
plot e7= open+e*7;
e7.setDefaultColor(createcolor(95,95,95));
e7.setStyle(curve.short_dash);
plot ex1= open-e;
ex1.setDefaultColor(createcolor(95,95,95));
ex1.setStyle(curve.short_dash);
plot ex3= open-e*3;
ex3.setDefaultColor(createcolor(95,95,95));
ex3.setStyle(curve.short_dash);
plot ex5= open-e*5;
ex5.setDefaultColor(createcolor(95,95,95));
ex5.setStyle(curve.short_dash);
plot ex7= open-e*7;
ex7.setDefaultColor(createcolor(95,95,95));
ex7.setStyle(curve.short_dash);

#quarter ATR
plot q1= open+q;
q1.setDefaultColor(createcolor(115,115,115));
q1.setStyle(curve.firm);
q1.setLineWeight(1);
plot q2= open+q*2;
q2.setDefaultColor(createcolor(115,115,115));
q2.setStyle(curve.firm);
q2.setLineWeight(1);
plot q3= open+q*3;
q3.setDefaultColor(createcolor(115,115,115));
q3.setStyle(curve.firm);
q3.setLineWeight(1);
plot qx1= open-q;
qx1.setDefaultColor(createcolor(115,115,115));
qx1.setStyle(curve.firm);
qx1.setLineWeight(1);
plot qx2= open-q*2;
qx2.setDefaultColor(createcolor(115,115,115));
qx2.setStyle(curve.firm);
qx2.setLineWeight(1);
plot qx3= open-q*3;
qx3.setDefaultColor(createcolor(115,115,115));
qx3.setStyle(curve.firm);
qx3.setLineWeight(1);

#sixteenth ATRs
plot s1= open+s;
s1.setDefaultColor(createcolor(85,85,85));
s1.setStyle(curve.short_dash);
plot s3= open+s*3;
s3.setDefaultColor(createcolor(85,85,85));
s3.setStyle(curve.short_dash);
plot s5= open+s*5;
s5.setDefaultColor(createcolor(85,85,85));
s5.setStyle(curve.short_dash);
plot s7= open+s*7;
s7.setDefaultColor(createcolor(85,85,85));
s7.setStyle(curve.short_dash);
plot s9= open+s*9;
s9.setDefaultColor(createcolor(85,85,85));
s9.setStyle(curve.short_dash);
plot s11= open+s*11;
s11.setDefaultColor(createcolor(85,85,85));
s11.setStyle(curve.short_dash);
plot s13= open+s*13;
s13.setDefaultColor(createcolor(85,85,85));
s13.setStyle(curve.short_dash);
plot s15= open+s*15;
s15.setDefaultColor(createcolor(85,85,85));
s15.setStyle(curve.short_dash);

plot sx1= open-s;
sx1.setDefaultColor(createcolor(85,85,85));
sx1.setStyle(curve.short_dash);
plot sx3= open-s*3;
sx3.setDefaultColor(createcolor(85,85,85));
sx3.setStyle(curve.short_dash);
plot sx5= open-s*5;
sx5.setDefaultColor(createcolor(85,85,85));
sx5.setStyle(curve.short_dash);
plot sx7= open-s*7;
sx7.setDefaultColor(createcolor(85,85,85));
sx7.setStyle(curve.short_dash);
plot sx9= open-s*9;
sx9.setDefaultColor(createcolor(85,85,85));
sx9.setStyle(curve.short_dash);
plot sx11= open-s*11;
sx11.setDefaultColor(createcolor(85,85,85));
sx11.setStyle(curve.short_dash);
plot sx13= open-s*13;
sx13.setDefaultColor(createcolor(85,85,85));
sx13.setStyle(curve.short_dash);
plot sx15= open-s*15;
sx15.setDefaultColor(createcolor(85,85,85));
sx15.setStyle(curve.short_dash);

#half ATR
plot h1 = open +h;
plot hx1 = open -h;
#top and bottom

#upper2.setdefaultColor(createcolor(95,95,95));

Always appreciate the help!
Cheers

Last edited by a moderator:
Solution
Round(value / 0.25,0) * 0.25
Round(value / 0.25,0) * 0.25

What's the updated code?

Rounding Issues Questions 6
Trailing ATR- show both levels at same time Questions 1
scan for ATR increase by x % Questions 0
ATR 99%percentile ,code Questions 1
ATR long or short Label in Watchlist Questions 2

87k+ Posts
442 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?