Relocate AddChartBubble to outside of chart

tlee404

Member
How do I get a Bubble to appear outside the chart like other Bubbles for studies such as MACD, SMA,etc? I have did some research but can't find any code to relocate the Bubble outside the chart. I created code to show the Close with a Bubble. But the Bubble is inside the chart.

Code:
#Daily Close
input aggregationPeriod = AggregationPeriod.DAY;
input showOnlyLastPeriod = yes;

def prevPrice = close(period = aggregationPeriod)[-1];
def price = close(period = aggregationPeriod);

plot DailyClose = if showOnlyLastPeriod and !IsNaN(prevPrice) then Double.NaN else price;
def x = DailyClose;
DailyClose.SetDefaultColor(GetColor(9));
DailyClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

AddChartBubble((x + 8) > DailyClose, close, close, Color.yellow, yes);

It appears my Question was truncated or changed. It should have been the same as the 1st sentence of my post.

After further research found the following.
  • The (x +8) > Daily Close, was not necessary, it only needed an x, you cannot use Close for it .
  • AddChartBubble((x + 8) > DailyClose, close,: if you add or subtract such as close +5, it will move the vertical position of the bubble.
But the amount moved seems to be dependent on the price of the stock and is not constant. It appears the bubble will appear on the right side of the candle, however if you don't have enough space on the right side of the chart to fit it, it will appear on the left side. This causes a problem as the close is the last candle on the chart so if you don't leave at least 6 extra candles spaces after the close the bubble will appear on the left side of the close. This makes it a problem when the previous prices are above the closing price of the day. As the bubble may conflict with other candles or bubbles. That is the reason I would have liked to have the bubble on the outside edge of the chart such as MACD, SMA,etc.

If your wondering, I coded this because I use Heikin Ashi candles, and as you know the closing price it shown is not the real closing price.
And I get tired of having to take the time to move my head to see the real closing price at the far left side of the chart. Also, I have a limited coding experience., but I can patch things together, which is how I created this after doing some research and sending hours to create it. You can be sure I will be asking for advice in the future. Hope this can help someone in the future.
 
Last edited by a moderator:
Solution
@tlee404 Noticed that your code definition for the variable "prevPrice", you're indexing 1 bar into the future. To index this as a bar before, your definition needs to be changed to

Code:
def prevPrice = close(period = aggregationPeriod)[1];

Your other comment about locating the bubble outside the chart - I take it you mean you'd like to display this in the expansion space?
Note that bubbles are located using an X, Y axis where X is the first variable usually denoted by a barNumber() or horizontal location and Y is the vertical or price location. Looking at your first variable for AddChartBubble() - that evaluates to a boolean rather than a horizontal location.

Hope that helps
@tlee404 Noticed that your code definition for the variable "prevPrice", you're indexing 1 bar into the future. To index this as a bar before, your definition needs to be changed to

Code:
def prevPrice = close(period = aggregationPeriod)[1];

Your other comment about locating the bubble outside the chart - I take it you mean you'd like to display this in the expansion space?
Note that bubbles are located using an X, Y axis where X is the first variable usually denoted by a barNumber() or horizontal location and Y is the vertical or price location. Looking at your first variable for AddChartBubble() - that evaluates to a boolean rather than a horizontal location.

Hope that helps
 
Solution
AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
PMHigh,
"PM High",
Color.Gray,
1);


How can I get chart bubble to show on right side of chart instead of showing up on top of highest bar.
Thanks
 
I am stuck and have been trying for like 4 hours already and cant figure out how to hide the green "addchartbubbles" that are LESS THAN 1,500,000 in volume, but i would still like for the actual blue volume bar to show, i just want the green bubbles under 1.5 million to hide. Any help would be much appreciated.

this is the code i have so far.

Code:
declare lower;

plot over = volume;
over.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
over.SetLineWeight(3);
AddChartBubble(high == high, high, "" + over, Color.green, no);

r95Xme3.png
 
Now I get a error message on the addchartbubble, I'm not even sure if I used double.NaN right, I don't really know how or when to use the nan syntax. Any way you can help a bit?

Code:
declare lower;

plot over = volume;
over.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
over.SetLineWeight(3);
AddChartBubble(high == high, high, "" + over, if  over > 1500000 then Color.green else  double.nan, no);

I even tried this and cant get it to work ... Anyone have any ideas what I'm doing wrong?

Code:
plot hvol = volume;
hvol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hvol.SetLineWeight(3);
AddChartBubble(yes, if  hvol  > 1500000 then "volume" + hvol  else "down", if hvol  < 1500000 then double.nan else color.green, no);
 
You're a life saver it worked, total different way of thinking, lol, coding is so interesting, shows how people think.

Quick question though, can you explain what the 0, hvol parameter does.

113O41z.png


Edit: I figured it out, its the distance up or down the 0 represents.

thanks again for the help
 
I would like to add a Chart Bubble to the code below; when the opentime is true place a Chart bubble at the high of the 5 minute close. For this time frame I would like the bubble text to show the word "Now" (I can change the text later.)

Code:
input opentime = 0400;
input ORend = 0405;
def na = Double.NaN;
#
# Check if the opening range time is now
#
def ORActive = if GetLastDay() == GetDay() and SecondsFromTime(opentime) >= 0 and SecondsFromTime(ORend) < 0 then 1 else 0;
#
# Track the OR high and low
#
def ORHigh = if ORActive then high else na;
def ORLow = if ORActive then low else na;
def ORLow2 = if ORActive then low else na;
#
# Plot the OR high and low
#
plot OHIGH = if GetLastDay() != GetDay() or !ORActive then na else HighestAll(ORHigh);
plot OLOW = if GetLastDay() != GetDay() or !ORActive then na else LowestAll(ORLow);
plot OLOW2 = if GetLastDay() != GetDay() or !ORActive then na else LowestAll(ORLow);
plot HIGH = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else HighestAll(ORHigh);
plot LOW = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else LowestAll(ORLow);
#
# Formatting
#
OHIGH.SetStyle(Curve.SHORT_DASH);
OLOW.SetStyle(Curve.SHORT_DASH);
OLOW2.SetStyle(Curve.SHORT_DASH);
OHIGH.SetDefaultColor(Color.GREEN);
OLOW.SetDefaultColor(Color.RED);
OLOW2.SetDefaultColor(Color.RED);
HIGH.SetStyle(Curve.SHORT_DASH);
LOW.SetStyle(Curve.SHORT_DASH);
HIGH.SetDefaultColor(Color.GREEN);
LOW.SetDefaultColor(Color.RED);
#
# Add Cloud creates the shading
#
AddCloud(OLOW, OHIGH, COLOR.WHITE, COLOR.WHITE, YES);
#
# Alerts:
#
def alerttrigger = if (high >= HIGH and low <= HIGH) or (high >= LOW and low <= LOW) then 1 else 0; #replace the 1 with your definition

# BLOCK CODE BELOW
input alerttext = "OR Breakout!";
input UseAlerts = {false, default true};
input AlertType = {default "BAR", "ONCE", "TICK"};
def at = AlertType;
input AlertSound = {"Bell", "Chimes", default "Ding", "NoSound", "Ring"};
Alert(alerttrigger and UseAlerts, alerttext, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);
 
Last edited by a moderator:
Can you add a Chart Bubble on a lower chart? I want to add a bubble on the Spearman when the length crosses below the average length in this code. The bubble text should say "Short" when crossing below and "Long" when crossing up:

Code:
declare lower;

input price = close;
input length = 7;
input averageLength = 3;
input over_bought = 80;
input over_sold = -80;

assert(length >= 2, "'length' must be greater than or equal to 2: " + length);

def sumSqr = fold i = 0 to length with sum do
sum + Sqr((length - i) - fold j = 0 to length with rank
do rank + if GetValue(price, i, length - 1) > GetValue(price, length - j - 1) or GetValue(price, i) == GetValue(price, length - j - 1) and i <= length - j - 1 then 1 else 0);

plot Spearman = 100 * (1 - 6 * sumSqr / (length * (Sqr(length) - 1)));
plot SpearmanAverage = Average(Spearman, averageLength);
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

Spearman.SetDefaultColor(GetColor(9));
SpearmanAverage.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));
 
Add this to the end of your script:

Code:
def condition1 = Spearman crosses above SpearmanAverage;
def condition2 = Spearman crosses below SpearmanAverage;

AddChartBubble(condition1, OverSold, "Long", Color.GREEN, no);
AddChartBubble(condition2, OverBought, "Short", Color.RED, yes);
 
Perfect as always! Thanks BenTen- I made a few additions based on what you provided.

Code:
declare lower;

input price = close;
input length = 10;
input averageLength = 3;
input over_bought = 80;
input over_sold = -80;

assert(length >= 2, "'length' must be greater than or equal to 2: " + length);

def sumSqr = fold i = 0 to length with sum do
sum + Sqr((length - i) - fold j = 0 to length with rank
do rank + if GetValue(price, i, length - 1) > GetValue(price, length - j - 1) or GetValue(price, i) == GetValue(price, length - j - 1) and i <= length - j - 1 then 1 else 0);

plot Spearman = 100 * (1 - 6 * sumSqr / (length * (Sqr(length) - 1)));
plot SpearmanAverage = Average(Spearman, averageLength);
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

Spearman.SetDefaultColor(GetColor(9));
SpearmanAverage.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));

def condition1 = Spearman crosses above SpearmanAverage;
def condition2 = Spearman crosses below SpearmanAverage;
def condition3= Spearman crosses above  ZeroLine;
def condition4= Spearman crosses below  ZeroLine;

AddChartBubble(condition1, OverSold, "B", Color.GREEN, yes);
AddChartBubble(condition2, OverBought, "S", Color.RED, yes);
AddChartBubble(condition3, OverSold, "Buy Above 0", Color.gray, yes);
AddChartBubble(condition4, OverBought, "Sell below 0", Color.gray, yes);
 
Last edited:
Hi All,

This is happening in a study I'm working on (not even close to being a functional study at this point): they are just solid black sometimes instead of showing a value - how to fix?

mOchqaK.jpg


Maybe the reason is something obvious but I absolutely can't figure out why this is happening.

The code for these bubbles is this:

Code:
AddChartBubble(close>0, plotmidD, SellvsBuyScoreRatioNorm, if VARIABLE1 then Color.Magenta else if VARIABLE2 then Color.Dark_orange else if VARIABLE3 then CreateColor(0, 100, 200) else if VARIABLE4 then Color.Yellow else if VARIABLE5 then Color.Gray else Color.Dark_gray, up = yes);

The code making up "SellvsBuyScoreRatioNorm" is this:

Code:
def DvgSellScorePercent = (DvgSellScore/356)*100;
def DvgBuyScorePercent = (DvgBuyScore/235)*100;

def SellvsBuyScoreRatio = (DvgSellScorePercent/(DvgBuyScorePercent+DvgSellScorePercent))*100;

def SellvsBuyScoreRatioNorm = normalizePlot(SellvsBuyScoreRatio,0,100);

The stuff for "DvgSellScore" and "DvgBuyScore" consists of a bunch of conditions like "if VARIABLEA then DvgSellScoreCounterA == 1 else 0".

The black empty bubbles still appear if I remove all the stuff for the color-coding (like if it's just "AddChartBubble(close>0, plotmidD, SellvsBuyScoreRatioNorm, Color.Gray, up=yes)" the same problem is happening) and it also happens if I have "SellvsBuyScoreRatio" there instead of the normalized "SellvsBuyScoreRatioNorm".

I'm really confused. I thought maybe it's because something is dividing by zero or something else weird but I can't find any such example (and even in that case it seems like the bubble should have "N/A" or something in it instead of being solid black and empty). Has anyone ever had this problem with chart bubbles before?

This is really odd. I'm reusing Welkin's Sigma value calculation code that is in his Advanced Volume study, and it turns out that when I reduce the length (e.g. from 20 to 3) then the number of black empty chart bubbles drastically decreases, even though whether or not I reference any of that code in the Chart Bubble content has no effect on how many of the bubbles appear black and empty:

Code:
def S_VolAverageType = AverageType.SIMPLE;
def S_AvgVolLength = 3;
#default is 20 length
def S_RelativetoPrevVolTolerance = 1.25;

def S_Vol = GetValue(SellvsBuyScoreRatio, 0);

def S_Num_Dev1 = 2.0;
def S_Num_Dev2 = 3.0;
def S_averageType = AverageType.SIMPLE;
def S_sDev = StDev(data = S_Vol, length = S_AvgVolLength);
def S_VolAvg = MovingAverage(S_VolAverageType, S_Vol, S_AvgVolLength);
def S_VolSigma2 = S_VolAvg + S_Num_Dev1 * S_sDev;
def S_VolSigma3 = S_VolAvg + S_Num_Dev2 * S_sDev;
def S_RelVol = S_Vol / S_VolAvg[1];
def S_RelPrevVol = S_Vol / S_Vol[1];

def S_RelVolPlotTriggerHighest = S_Vol > S_VolSigma3;
def S_RelVolPlotTriggerHigh = (S_Vol < S_VolSigma3) and ( S_Vol > S_VolSigma2 );
def S_RelVolPlotTriggerMid = ( S_Vol < S_VolSigma2 ) and (S_Vol > S_VolAvg);
def S_RelVolPlotTriggerLow = (S_Vol < S_VolAvg) and (S_RelPrevVol >= S_RelativetoPrevVolTolerance);
def S_RelVolPlotTriggerLowest = S_RelPrevVol < S_RelativetoPrevVolTolerance;

It's quite beyond me to understand how these are related and so I am not interested in trying to "fix" what is happening here (for my purposes, I am just going to reduce the length of the averaging to 3, which eliminates almost all of the black chart bubbles). I would still however be very interested if anyone knows what the chart bubbles being solid black means in general (e.g. is it some kind of glitch or N/A result that is predictable under certain conditions).
 
Last edited by a moderator:
Can you relocate a ChartBubble to the left side of the chart of a plotted line? The following code places the chart bubble at the right most side of the chart on the line which interferes with viewing the most recent candle action. I would like to locate the bubble to the left side of the line on the screen:

Code:
AddChartBubble(bubbles && bn == cb, priorRTHhigh, "Yhigh", Color.CYAN);

priorRTHhigh is the plot.

This doesn't work.

Code:
AddChartBubble(bubbles && bn == cb, left,  priorRTHhigh, "Yhigh", Color.CYAN);

I couldn't find anything in the manual or from search here. Thanks in advance.
 
I know for sure when AddChartBubble is assigned to a candlestick, you can move it to the top or bottom of the candle, but I'm not sure if you can relocate the bubble from right to left, especially when attached to a horizontal line.
 
figured that was the case. i only wanted the chart bubble to appear if the the plot line was visible. i was plotting high lows from yesterday and premarket, etc. but the bubbles always show up even if the the plot line is not visible. oh well. thx anyways
 
I see my question got moved to this thread so I thought I would post how I put my chart bubbles on the left side so they are easy to see. I've seen a lot of people ask about it, so maybe someone can use it.

Code:
def bubblebar = !IsNaN(myClose) and IsNaN(myClose[-1]);
AddChartBubble(showChartBubbles and bubblebar[15], yClose, "yClose" Color.LIGHT_GRAY);

It places the chart bubble 15 bars after the current bar. just change it to whatever you want.
 
I'm trying to add a text label to the add bubble, and for some reason its adding a green bubble for upstep at both the upstep and downstep.
2 1 questions;

1) Why is adding my label to both upstep and downstep? it plots the arrows at the perfect location. and it appears it maybe isn't showing every arrow.

2) when I place the upstep, it doesn't let me place it ... never mind I solved this by changing the area after the first comma to "close + 5", as seen in the addchartbubble section of the code below.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2013-2021
#

input priceH = high;
input priceL = low;
input percentageReversal = 5.0;
input absoluteReversal = 0.0;
input atrLength = 5;
input atrReversal = 1.5;

def zigZag = reference ZigZagHighLow(priceH, priceL, percentageReversal, absoluteReversal, atrLength, atrReversal).ZZ;

def step1 = open[1] >= open and open >= close[1] and open[1] > close[1];
def step2 = open[1] <= open and open <= close[1] and open[1] < close[1];

def upStep1 = step1 and close > open[1];
def upStep2 = step2 and close > close[1];
def downStep1 = step1 and close < close[1];
def downStep2 = step2 and close < open[1];

plot UpStep = (upStep1 or upStep1[-1] or upStep2 or upStep2[-1]) and zigZag == low;
plot DownStep = (downStep1 or downStep1[-1] or downStep2 or downStep2[-1]) and zigZag == high;

UpStep.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpStep.SetDefaultColor(GetColor(6));
UpStep.SetLineWeight(1);
DownStep.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownStep.SetDefaultColor(GetColor(5));
DownStep.SetLineWeight(1);

addchartBubble((!IsNaN(upstep)), close + 5, "upstep", color.red, yes);
addchartBubble((!IsNaN(downstep)), close - 5, "downstep", color.green, yes);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
262 Online
Create Post

Similar threads

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