Help me Add Chart Bubble on previous candle

T

TigerWares

New member
This is what I have

AddChartBubble(pl, low, "PL", Color.WHITE, no);

It comes up fine but I want it to display on the previous candle not the current one.

Can't find anything on Google.
 
rad14733

rad14733

Well-known member
VIP
Code:
AddChartBubble(pl, low[1], "PL", Color.WHITE, no);
 
T

TigerWares

New member
AddChartBubble(pl, low[1], "PL", Color.WHITE, no);

Yeah, I actually tried that before. It just moves the bubble closer or farther away from the candle.

I thought maybe BarNumber but don't really understand that
 
rad14733

rad14733

Well-known member
VIP
Yeah, I actually tried that before. It just moves the bubble closer or farther away from the candle.

I thought maybe BarNumber but don't really understand that
I haven't found anything that indicates that AddChartBubble() can be relocated to a different bar like AddOrder() can... :cautious:
 
X

XeoNoX

Member
in a sense your right tigerwares.... it can be done by defining the time frame and then selecting the bar you want to move the label for and insterting a [-1] or [+1] depending on the direction you want to shift it. The code provided by @korygill works quite well.



Code:
# GetDayValues
# Author: Kory Gill, @korygill
#
# VERSION HISTORY (sortable date and time (your local time is fine), and your initials
# 20190823-1400-KG    - Created.
# ...
# ...
declare hide_on_daily;
declare once_per_bar;

input onUpper = yes;

#
# logic
#
def nan = Double.NaN;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBarOfDay = if
    (afterEnd[-1] == 1 and afterEnd == 0) or
    (isRollover[-1] and firstBarOfDay[-1])
    then 1
    else 0;

#
# Identify first bar of day and last bar of day on chart
#
AddChartBubble(
    firstBarOfDay and onUpper,
    close,
    "First Bar of Day",
    Color.GREEN,
    yes);

AddChartBubble(
    lastBarOfDay and onUpper,
    close,
    "Last Bar of Day",
    Color.GREEN,
    no);

#
# plots
#
plot p1 = if !onUpper then isRollover else nan;
plot p2 = if !onUpper then beforeStart else nan;
plot p3 = if !onUpper then afterEnd else nan;
plot p4 = if !onUpper then firstBarOfDay else nan;
plot p5 = if !onUpper then lastBarOfDay else nan;

p1.SetDefaultColor(GetColor(1));
p2.SetDefaultColor(GetColor(2));
p3.SetDefaultColor(GetColor(3));
p4.SetDefaultColor(GetColor(4));
p5.SetDefaultColor(GetColor(5));

AddLabel(!onUpper, "isRollOver", GetColor(1));
AddLabel(!onUpper, "beforeStart", GetColor(2));
AddLabel(!onUpper, "afterEnd", GetColor(3));
AddLabel(!onUpper, "firstBarOfDay", GetColor(4));
AddLabel(!onUpper, "lastBarOfDay", GetColor(5));
 

Similar threads

Top