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
 

BenTen

Administrative
Staff
VIP

XeoNoX

Well-known member
VIP
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:

SleepyZ

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

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
 

Similar threads

Top