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##
def h= adr_10/2; #half ATR
def q= adr_10/4; #quarter ATR
def e= adr_10/8; #eighth ATR
def s= adr_10/16; #sixteenth ATR

#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
plot top = open+adr_10;
plot bottom = open-adr_10;


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

Always appreciate the help!
Cheers
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
492 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top