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.
 
Solution
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() >...

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

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.
 

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

Administrative
Staff member
Staff
VIP
Lifetime
@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);
 

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

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

Wiinii

New member
See if this helps

I think maxismiami was asking how to get this code to move one candle to the left:

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

Your code does something quite different. Can you help?
 

Wiinii

New member
I seem to have it working, but is there any way to only make it show on the last candle vs every last candle?

Code:
#Previous Candle High/Low Bubbles
input bubblemoversideways = -1;
def b  = bubblemoversideways;
def b1 = b + 1;
input bubblemoverupdown   = 3;
AddChartBubble(round(low[b]), high[b] + bubblemoverupdown * TickSize(), "PCL " + round(low), Color.WHITE);
AddChartBubble(round(high[b]), high[b] + bubblemoverupdown * TickSize(), "PCH" + round(high), Color.YELLOW);
 
Last edited:

SleepyZ

Well-known member
VIP
Lifetime
I seem to have it working, but is there any way to only make it show on the last candle vs every last candle?

Code:
#Previous Candle High/Low Bubbles
input bubblemoversideways = -1;
def b  = bubblemoversideways;
def b1 = b + 1;
input bubblemoverupdown   = 3;
AddChartBubble(round(low[b]), high[b] + bubblemoverupdown * TickSize(), "" + round(low), Color.WHITE);
AddChartBubble(round(high[b]), high[b] + bubblemoverupdown * TickSize(), "" + round(high), Color.YELLOW);/CODE]

You can add something between the quotes if you want it to say something.

This should help. It is compilation of the codes on this thread using the bubblemover code and hard coded offsets to move the bubble displaying the previous candles values one bar left of the current candle. The bubblemover is just a more flexible way of moving bubbles wherever you want.

You are right, I must not in my original response to @maxismiami, clicked open his request to see his example, and my response was just a general way to move bubbles.

Hope this helps
Capture.jpg
Ruby:
#High/low bubbles for the previous candle
input bubblemoversideways = -2;
def b  = bubblemoversideways;
def b1 = b + 1;
input bubblemoverupdown   = 3;

Addchartbubble(!isnan(close[b1]) and isnan(close[b]), low[b1+1], "Low previous candle: " +low[b1+1], color.violet);
Addchartbubble(!isnan(close[b1]) and isnan(close[b]), high[b1+1], "Hi previous candle: " +high[b1+1], color.violet);

def PCH = round(high);
def PCL = round(low);

AddChartBubble(!isnan(close[b1]) and isnan(close[b]), high[b1+1] + bubblemoverupdown * TickSize(), "" + PCH[b1+1], Color.YELLOW);

#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]) and isnan(close[-2]), hl[0], "Low(2): " +hl[0], color.violet, no);
Addchartbubble(!isnan(close[-1]) and isnan(close[-2]), hh[0], "Hi(2): " +hh[0], color.violet, yes);
 

Wiinii

New member
This should help. It is compilation of the codes on this thread using the bubblemover code and hard coded offsets to move the bubble displaying the previous candles values one bar left of the current candle. The bubblemover is just a more flexible way of moving bubbles wherever you want.

You are right, I must not in my original response to @maxismiami, clicked open his request to see his example, and my response was just a general way to move bubbles.

Hope this helps

You are the man, thank you so much!!! I have a feeling this one will be quite popular!

Here is my final edit from yours:

Code:
#High/low bubbles for the previous candle (change color/transparency under Globals)
input bubblemoversideways = -2;
def b  = bubblemoversideways;
def b1 = b + 1;
input bubblemoverupdown   = 3;
DefineGlobalColor("high", Color.YELLOW);
DefineGlobalColor("low", Color.WHITE);

Addchartbubble(!isnan(close[b1]) and isnan(close[b]), low[b1+1], "PC Low" +round(low[b1+1]), GlobalColor("low"));
Addchartbubble(!isnan(close[b1]) and isnan(close[b]), high[b1+1], "PC High " +round(high[b1+1]), GlobalColor("high"));

EDIT: Added color and transparency options for the bubbles, under Globals.
 
Last edited:

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.
Top