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]) ;
AddChartBubble(cond, line0, "0% Mo", Color.downtick);
AddChartBubble(cond, line_100, "100% Mo", Color.downtick);
AddChartBubble(cond, line100, "-100% Mo", Color.downtick);
AddChartBubble(cond, line035, "-3.5% Mo", Color.downtick);
AddChartBubble(cond, line_035, "3.5% Mo", Color.downtick);
AddChartBubble(cond, line_7, "7% Mo", Color.downtick);
AddChartBubble(cond, line7, "-7% Mo", Color.downtick);
AddChartBubble(cond, line_13, "13% Mo", Color.downtick);
AddChartBubble(cond, line13, "-13% Mo", Color.downtick);
AddChartBubble(cond, line_20, "20% Mo", Color.downtick);
AddChartBubble(cond, line20, "-20% Mo", Color.downtick);
AddChartBubble(cond, line_33, "33% Mo", Color.downtick);
AddChartBubble(cond, line33, "-33% Mo", Color.downtick);
AddChartBubble(cond, line_67, "67% Mo", Color.downtick);
AddChartBubble(cond, line67, "-67% Mo", Color.downtick);

#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);



as for your question of
"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]) ;
AddChartBubble(cond, line0, "0% Mo", Color.downtick);
AddChartBubble(cond, line_100, "100% Mo", Color.downtick);
AddChartBubble(cond, line100, "-100% Mo", Color.downtick);
AddChartBubble(cond, line035, "-3.5% Mo", Color.downtick);
AddChartBubble(cond, line_035, "3.5% Mo", Color.downtick);
AddChartBubble(cond, line_7, "7% Mo", Color.downtick);
AddChartBubble(cond, line7, "-7% Mo", Color.downtick);
AddChartBubble(cond, line_13, "13% Mo", Color.downtick);
AddChartBubble(cond, line13, "-13% Mo", Color.downtick);
AddChartBubble(cond, line_20, "20% Mo", Color.downtick);
AddChartBubble(cond, line20, "-20% Mo", Color.downtick);
AddChartBubble(cond, line_33, "33% Mo", Color.downtick);
AddChartBubble(cond, line33, "-33% Mo", Color.downtick);
AddChartBubble(cond, line_67, "67% Mo", Color.downtick);
AddChartBubble(cond, line67, "-67% Mo", Color.downtick);

#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);


AddChartBubble(cond, line0, "0% Mo", Color.downtick);
AddChartBubble(cond, line_100, "100% Mo", Color.downtick);
AddChartBubble(cond, line100, "-100% Mo", Color.downtick);
AddChartBubble(cond, line035, "-3.5% Mo", Color.downtick);
AddChartBubble(cond, line_035, "3.5% Mo", Color.downtick);
AddChartBubble(cond, line_7, "7% Mo", Color.downtick);
AddChartBubble(cond, line7, "-7% Mo", Color.downtick);
AddChartBubble(cond, line_13, "13% Mo", Color.downtick);
AddChartBubble(cond, line13, "-13% Mo", Color.downtick);
AddChartBubble(cond, line_20, "20% Mo", Color.downtick);
AddChartBubble(cond, line20, "-20% Mo", Color.downtick);
AddChartBubble(cond, line_33, "33% Mo", Color.downtick);
AddChartBubble(cond, line33, "-33% Mo", Color.downtick);
AddChartBubble(cond, line_67, "67% Mo", Color.downtick);
AddChartBubble(cond, line67, "-67% Mo", Color.downtick);
Capture.jpg
 

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
230 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