# Plotted lines and positioning of bubbles

#### RickK

##### Active member
Hey all,

I've been working on a project that will plot certain lines based on a certain calculation and I was able to piece together some
code from a pivot points indicator. It does a great job of plotting the lines and the bubbles, but I have a couple of
questions. Currently, the lines will be plotted into perpetuity to the left and into perpetuity to the right.

1. Is there a way to have the lines begin on a futures contract roll date and end on the next roll? ... but without having to set my chart to a minimum of a 1 month period?
2. Is there a way to get the bubbles to display at the plotted lines even if I scroll back 1, 5, 10 days?

Here's the code:

Code:
``````input anchor = 3883.40;
input factor = 1.173;
input showbubble = yes;
input shiftbubble = 0;

def n1 = shiftbubble + 1;
def target = anchor * factor;

plot line0 = anchor;
plot line_100 = anchor * factor * -1;
plot line100 = anchor * factor;
plot line_035 = anchor - ((target - anchor) * -0.035);
plot line035 = anchor - ((target - anchor) * 0.035);
plot line_7 = anchor - ((target - anchor) * -0.07);
plot line7 = anchor - ((target - anchor) * 0.07);
plot line_13 = anchor - ((target - anchor) * -0.13);
plot line13 = anchor - ((target - anchor) * 0.13);
plot line_20 = anchor - ((target - anchor) * -0.20);
plot line20 = anchor - ((target - anchor) * 0.20);
plot line_33 = anchor - ((target - anchor) * -0.33);
plot line33 = anchor - ((target - anchor) * 0.33);
plot line_67 = anchor - ((target - anchor) * -0.67);
plot line67 = anchor - ((target - anchor) * 0.67);

line0.SetDefaultColor(Color.downtick);
line_100.SetDefaultColor(Color.downtick);
line100.SetDefaultColor(Color.downtick);
line_035.SetDefaultColor(Color.downtick);
line035.SetDefaultColor(Color.downtick);
line_7.SetDefaultColor(Color.downtick);
line7.SetDefaultColor(Color.downtick);
line_13.SetDefaultColor(Color.downtick);
line13.SetDefaultColor(Color.downtick);
line_33.SetDefaultColor(Color.downtick);
line33.SetDefaultColor(Color.downtick);
line_67.SetDefaultColor(Color.downtick);
line67.SetDefaultColor(Color.downtick);
line_20.SetDefaultColor(Color.downtick);
line20.SetDefaultColor(Color.downtick);

def cond = showbubble and IsNaN(close[shiftbubble]) and !IsNaN(close[n1]) ;

#end``````

you would have to manually input the dates, but perhaps something like this :

Code:
``````input anchor = 3883.40;
input factor = 1.173;
input showbubble = yes;
input shiftbubble = 0;
input date = 20210315; #YYYY - MM - DD
def isdate = GetYYYYMMDD()==date;
def n1 = shiftbubble + 1;
def target = anchor * factor;
def line0 = anchor;
def bar =  if  isdate  and line0 then line0 else Bar[1];
plot LineZero = if  !isdate  then double.nan else HighestAll(Bar);
LineZero.SetStyle(Curve.SHORT_DASH);
LineZero.SetDefaultColor(Color.green);``````

or something like this:

Code:
``````input anchor = 3883.40;
input factor = 1.173;
input showbubble = yes;
input shiftbubble = 0;
def n1 = shiftbubble + 1;
def target = anchor * factor;
def line0 = anchor;
input startdate = 20210315;
input endDate = 20210324;
def cond = GetYYYYMMDD() > startDate and GetYYYYMMDD() < endDate;
plot linezero = if cond then line0 else Double.NaN;
LineZero.SetStyle(Curve.SHORT_DASH);
LineZero.SetDefaultColor(Color.green);``````

"Is there a way to get the bubbles to display at the plotted lines even if I scroll back 1, 5, 10 days?"

No, but you can make a label using "addlabel" that would show

Last edited:
Hey all,

I've been working on a project that will plot certain lines based on a certain calculation and I was able to piece together some
code from a pivot points indicator. It does a great job of plotting the lines and the bubbles, but I have a couple of
questions. Currently, the lines will be plotted into perpetuity to the left and into perpetuity to the right.

1. Is there a way to have the lines begin on a futures contract roll date and end on the next roll? ... but without having to set my chart to a minimum of a 1 month period?
2. Is there a way to get the bubbles to display at the plotted lines even if I scroll back 1, 5, 10 days?

Here's the code:

Code:
``````input anchor = 3883.40;
input factor = 1.173;
input showbubble = yes;
input shiftbubble = 0;

def n1 = shiftbubble + 1;
def target = anchor * factor;

plot line0 = anchor;
plot line_100 = anchor * factor * -1;
plot line100 = anchor * factor;
plot line_035 = anchor - ((target - anchor) * -0.035);
plot line035 = anchor - ((target - anchor) * 0.035);
plot line_7 = anchor - ((target - anchor) * -0.07);
plot line7 = anchor - ((target - anchor) * 0.07);
plot line_13 = anchor - ((target - anchor) * -0.13);
plot line13 = anchor - ((target - anchor) * 0.13);
plot line_20 = anchor - ((target - anchor) * -0.20);
plot line20 = anchor - ((target - anchor) * 0.20);
plot line_33 = anchor - ((target - anchor) * -0.33);
plot line33 = anchor - ((target - anchor) * 0.33);
plot line_67 = anchor - ((target - anchor) * -0.67);
plot line67 = anchor - ((target - anchor) * 0.67);

line0.SetDefaultColor(Color.downtick);
line_100.SetDefaultColor(Color.downtick);
line100.SetDefaultColor(Color.downtick);
line_035.SetDefaultColor(Color.downtick);
line035.SetDefaultColor(Color.downtick);
line_7.SetDefaultColor(Color.downtick);
line7.SetDefaultColor(Color.downtick);
line_13.SetDefaultColor(Color.downtick);
line13.SetDefaultColor(Color.downtick);
line_33.SetDefaultColor(Color.downtick);
line33.SetDefaultColor(Color.downtick);
line_67.SetDefaultColor(Color.downtick);
line67.SetDefaultColor(Color.downtick);
line_20.SetDefaultColor(Color.downtick);
line20.SetDefaultColor(Color.downtick);

def cond = showbubble and IsNaN(close[shiftbubble]) and !IsNaN(close[n1]) ;

#end``````

See if the helps. Added is an option to showonlylastPeriod or all periods and modified your cond statement.
Code:
``````input anchor = 3883.40;
input factor = 1.173;
input showbubble = yes;
input shiftbubble = 0;
input showonlyLastPeriod = yes;

def n1 = shiftbubble + 1;
def target = anchor * factor;
def cond = showbubble and
if showonlyLastPeriod==yes then isnan(close[shiftbubble]) and !isnan(close[n1])
else getyyyYMMDD()!=getyyyyMMDD()[1];

plot line0 = anchor;
plot line_100 = anchor * factor * -1;
plot line100 = anchor * factor;
plot line_035 = anchor - ((target - anchor) * -0.035);
plot line035 = anchor - ((target - anchor) * 0.035);
plot line_7 = anchor - ((target - anchor) * -0.07);
plot line7 = anchor - ((target - anchor) * 0.07);
plot line_13 = anchor - ((target - anchor) * -0.13);
plot line13 = anchor - ((target - anchor) * 0.13);
plot line_20 = anchor - ((target - anchor) * -0.20);
plot line20 = anchor - ((target - anchor) * 0.20);
plot line_33 = anchor - ((target - anchor) * -0.33);
plot line33 = anchor - ((target - anchor) * 0.33);
plot line_67 = anchor - ((target - anchor) * -0.67);
plot line67 = anchor - ((target - anchor) * 0.67);

line0.SetDefaultColor(Color.downtick);
line_100.SetDefaultColor(Color.downtick);
line100.SetDefaultColor(Color.downtick);
line_035.SetDefaultColor(Color.downtick);
line035.SetDefaultColor(Color.downtick);
line_7.SetDefaultColor(Color.downtick);
line7.SetDefaultColor(Color.downtick);
line_13.SetDefaultColor(Color.downtick);
line13.SetDefaultColor(Color.downtick);
line_33.SetDefaultColor(Color.downtick);
line33.SetDefaultColor(Color.downtick);
line_67.SetDefaultColor(Color.downtick);
line67.SetDefaultColor(Color.downtick);
line_20.SetDefaultColor(Color.downtick);
line20.SetDefaultColor(Color.downtick);

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