• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Help me Add Chart Bubble on previous candle

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

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:
 

XeoNoX

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

Fvw5tlQ.png


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

jokajon00

New member
I would like to know how or if its possible to make a script that shows the low/high of the previous candle. I've tried searching and only found something in regards to a 5 minute candle, but that didn't work and when I tried to modify it I could only get the high and low of the current candle. I know if you hover you can see it but thats too small. Thanks in advance.
 

MerryDay

Well-known member
VIP
@jokajon00 you didn't provide the script that you are trying to modify. So I cannot provide the whole statement but:
Code:
# The syntax for referring to the high and low of the previous candle is:
high[1]
low[1]
HTH
 

jokajon00

New member
@MerryDay This is the script I'm trying to modify to make it show high and low of previous candle on any chart, but if i have to be specific on the 1 minute chart:

Thanks

Code:
#hint: High/low bubbles on last candle
input count = 5;
def l = low(period = aggregationperiod.FIVE_MIN);
def h = high(period = aggregationperiod.FIVE_MIN);
def FiveBarLow = lowest(l,count);
def FiveBarHigh = highest(h,count);
def LastBar = if IsNan(Close[-1]) then 1 else 0;
Addchartbubble(LastBar, low, "Lowest in Last 5 Minutes: " + FiveBarLow, color.white, no);
Addchartbubble(LastBar, high, "Highest in Last 5 Minutes: " + FiveBarHigh, color.white, yes);
 

jokajon00

New member
@MerryDay so far I have modified it to this and it seems to show the high price and low price over the last 2 minutes, but I just want to add chart bubble that say the high and low of the previous candle. ideally on any timeframe, but if I have to pick 1 minute timeframe. Thanks again
Code:
#hint: High/low bubbles on last candle
input count = 2;
def l = low(period = aggregationperiod.MIN);
def h = high(period = aggregationperiod.MIN);
def FiveBarLow = lowest(l,count);
def FiveBarHigh = highest(h,count);
def LastBar = if IsNan(Close[-1]) then 1 else 0;
Addchartbubble(LastBar, low, "Low(2): " + FiveBarLow, color.white, no);
Addchartbubble(LastBar, high, "Hi(2): " + FiveBarHigh, color.white, yes);
 

MerryDay

Well-known member
VIP
@jokajon00 very nice first try!
For studies to work on any timeframe there can not be any 'overriding' aggregation period.
Also as there is no request for the lowest or highest of a range of candles, there is no need for the lowest or highest statements.
This leaves the code looking like this:
Ruby:
#High/low bubbles for the previous candle
Addchartbubble(isnan(close[-1]), low, "Low previous candle: " +low[1], color.violet);
Addchartbubble(isnan(close[-1]), high, "Hi previous candle: " +high[1], color.violet);
NRb8AvK.png

HTH
 

jokajon00

New member
@MerryDay awesome. just realized its taking price from regular candle. So I did a search for some Hekin-Ashi scripts and came to this for HA high and HA low of prev candle. Seems to be working, but just want to make sure code is right. Thanks
Code:
#Heikin-Ashi Hi-Low Previous Candle
def hc = (open + high + low + close ) / 4;
def ho = CompoundValue( 1, ( ho[1] + hc[1] ) / 2, hc );
def hh = Max(Max(high , ho), hc);
def hl = Min(Min(low , ho), hc);

Addchartbubble(isnan(close[-1]), hl, "Low(2): " +hl[1], color.violet, no);
Addchartbubble(isnan(close[-1]), hh, "Hi(2): " +hh[1], color.violet, yes);
 

jokajon00

New member
@MerryDay tried searching all over but can't seem to figure out if this is possible, but anyway to set it so when a Heikin ashi chart style is selected it uses the HA formulas for high and low and when its regular candle or any other chart it uses the regular high and low values?

closest i could come was a way to change it via inputs, but if it automatically changed when i changed my chart type that would be better. here's what i have:
Code:
#Heikin-Ashi
def hc;
def ho;
def hh;
def hl;
input ChartType = {default HEIKIN_ASHI, CANDLE};
if (ChartType == ChartType.HEIKIN_ASHI)

{
    hc = (open + high + low + close ) / 4;
    ho = CompoundValue( 1, ( ho[1] + hc[1] ) / 2, hc );
    hh = Max(Max(high , ho), hc);
    hl = Min(Min(low , ho), hc);
}
else
{
    hc = (open + high + low + close ) / 4;
    ho = CompoundValue( 1, ( ho[1] + hc[1] ) / 2, hc );
    hh = high;
    hl = low;
}


input labellow = yes;
AddLabel(labellow and yes, Concat("Low(Prev) = ", Round(hl[1], 2)),  Color.VIOLET);
input labelhigh = yes;
AddLabel(labelhigh and yes, Concat("Hi(Prev) = ", Round(hh[1], 2)),  Color.VIOLET);

input showBubblesHigh = yes;
input showBubblesLow = yes;
AddChartBubble(showBubblesLow and IsNaN(close[-1]), hl * 0.97, "Low(Prev): " + Round(hl[1], 2), Color.VIOLET, no);
AddChartBubble(showBubblesHigh and IsNaN(close[-1]), hh * 1.03, "Hi(Prev): " + Round(hh[1], 2), Color.VIOLET, yes);
 
Last edited:

maxismiami

New member
@jokajon00 very nice first try!
For studies to work on any timeframe there can not be any 'overriding' aggregation period.
Also as there is no request for the lowest or highest of a range of candles, there is no need for the lowest or highest statements.
This leaves the code looking like this:
Ruby:
#High/low bubbles for the previous candle
Addchartbubble(isnan(close[-1]), low, "Low previous candle: " +low[1], color.violet);
Addchartbubble(isnan(close[-1]), high, "Hi previous candle: " +high[1], color.violet);
NRb8AvK.png

HTH
Is there a way for the bubble to be displayed on the previous candle and not on the current candle?

Have been trying to find something similar to this one https://www.tradingview.com/v/c02nPtMK/
 

SleepyZ

Active member
Is there a way for the bubble to be displayed on the previous candle and not on the current candle?

Have been trying to find something similar to this one https://www.tradingview.com/v/c02nPtMK/
See if this helps
Code:
#Addchartbubble_Display High @candle to left of Conditional Candle Displaying High of Candle to Left

plot ma1 = Average(close, 2);
plot ma2 = Average(close, 5);
def cond = ma1 crosses above ma2;

#Bubble placed where cond happened displaying the cond high
AddChartBubble(cond, high, high, Color.MAGENTA);

#Bubble placed @High of Previous Candle to the Conditional Candle
addchartbubble(cond[-1],high[0],high[0],color.white);
Capture.jpg
 
Last edited:

Similar threads

Top