# pivot_labels_bubbles_00
def bn = barnumber();
def na = double.nan;
# read pivot values from the study, PivotPoints()
def r3 = round(PivotPoints().r3,2);
def r2 = round(PivotPoints().r2,2);
def r1 = round(PivotPoints().r1,2);
def pp = round(PivotPoints().pp,2);
def s1 = round(PivotPoints().s1,2);
def s2 = round(PivotPoints().s2,2);
def s3 = round(PivotPoints().s3,2);
# display differences of close - pivots in labels
input show_labels = yes;
addlabel(show_labels, "S3: " + s3 + " diff: " + round(s3 - close,2), ( if s3 > close then color.green else color.red) );
addlabel(show_labels, "S2: " + s2 + " diff: " + round(s2 - close,2), ( if s2 > close then color.green else color.red) );
addlabel(show_labels, "S1: " + s1 + " diff: " + round(s1 - close,2), ( if s1 > close then color.green else color.red) );
addlabel(show_labels, "PP: " + pp + " diff: " + round(pp - close,2), ( if pp > close then color.green else color.red) );
addlabel(show_labels, "R1: " + r1 + " diff: " + round(r1 - close,2), ( if r1 - close then color.green else color.red) );
addlabel(show_labels, "R2: " + r2 + " diff: " + round(r2 - close,2), ( if r2 - close then color.green else color.red) );
addlabel(show_labels, "R3: " + r3 + " diff: " + round(r3 - close,2), ( if r3 - close then color.green else color.red) );
input bubble_offset = 3;
def off = bubble_offset + 1;
def x = if (!isnan(close[bubble_offset + 1]) and isnan(close[bubble_offset])) then 1 else 0;
def cls2 = close[off];
input show_bubbles = yes;
addchartbubble(show_bubbles and x, s3[off] , "S3: " + s3[off] + " diff: " + round(s3[off] - cls2,2), ( if s3[off] > cls2 then color.green else color.red), no);
addchartbubble(show_bubbles and x, s2[off] , "S2: " + s2[off] + " diff: " + round(s2[off] - cls2,2), ( if s2[off] > cls2 then color.green else color.red), no);
addchartbubble(show_bubbles and x, s1[off] , "S1: " + s1[off] + " diff: " + round(s1[off] - cls2,2), ( if s1[off] > cls2 then color.green else color.red), no);
addchartbubble(show_bubbles and x, pp[off] , "PP: " + pp[off] + " diff: " + round(pp[off] - cls2,2), ( if pp[off] > cls2 then color.green else color.red), no );
addchartbubble(show_bubbles and x, r1[off] , "R1: " + r1[off] + " diff: " + round(r1[off] - cls2,2), ( if r1[off] > cls2 then color.green else color.red), yes);
addchartbubble(show_bubbles and x, r2[off] , "R2: " + r2[off] + " diff: " + round(r2[off] - cls2,2), ( if r2[off] > cls2 then color.green else color.red), yes);
addchartbubble(show_bubbles and x, r3[off] , "R3: " + r3[off] + " diff: " + round(r3[off] - cls2,2), ( if r3[off] > cls2 then color.green else color.red), yes);
# draw lines at pivot levels, for x bars
#input line_length = 20;
#def xline = if (bn > line_length and ( !isnan(close) and isnan(close[-line_length]))) then 1 else 0;
# draw lines at pivot levels, on the current day
def xline = if getday() == getlastday() then 1 else 0;
plot s3line = if xline then s3 else na;
plot s2line = if xline then s2 else na;
plot s1line = if xline then s1 else na;
plot ppline = if xline then pp else na;
plot r1line = if xline then r1 else na;
plot r2line = if xline then r2 else na;
plot r3line = if xline then r3 else na;
s3line.setdefaultcolor(color.gray);
s2line.setdefaultcolor(color.gray);
s1line.setdefaultcolor(color.gray);
ppline.setdefaultcolor(color.gray);
r1line.setdefaultcolor(color.gray);
r2line.setdefaultcolor(color.gray);
s3line.setdefaultcolor(color.gray);
#