BubbleMover Code Snippet for ThinkOrSwim

TigerWares

New member
VIP
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.
 
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));
 
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 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);
 
@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
 
@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 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/
 
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:
This will allow you to move your bubbles sideways and/or up/down, but unfortunately TOS will not allow you to change the bubbles sideway's orientation. The following chart shows the moved bubbles in yellow Just change the inputs to move the bubbles to your liking.

04-08-2021-12-49-24-REC.png

Ruby:
def sellsignal = close crosses below Average(close, 20);

input bubblemoversideways = -1;
def b  = bubblemoversideways;
def b1 = b + 1;
input bubblemoverupdown   = 3;

AddChartBubble(sellsignal[b] and !IsNaN(close[b1]), high[b] + bubblemoverupdown * TickSize(), "Sell", Color.YELLOW, yes);
 
Last edited by a moderator:
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?
 
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:
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);
 
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:
Hi All,

I'd like to put the RR chart bubbles to the right of the current bar a few bars into the future. Is this possible to do? Currently the RR bubble on the current candle is hindering my view. If its not possible to push the bubbles to the right, am I able to eliminate the bubble on each current bar so that my view isn't hindered? I've searched existing studies but haven't been able to find the right code. Thanks in advance!


Code:
input marketThreshold = 0.0025;
input timeFrameDay = {default DAY};
input applyPersonsLevelsFilter = yes;

assert(marketThreshold >= 0, "'market threshold' must not be negative: " + marketThreshold);

def marketType = {default DISABLED, NEUTRAL, BEARISH, BULLISH};

def PP2 = high(period = timeFrameDay)[2] + low(period = timeFrameDay)[2] + close(period = timeFrameDay)[2];

marketType = if !applyPersonsLevelsFilter then marketType.DISABLED else
if PP2[-1] > (PP2[-1] + PP2 + PP2[1]) / 3 + marketThreshold then marketType.BULLISH else
if PP2[-1] < (PP2[-1] + PP2 + PP2[1]) / 3 - marketThreshold then marketType.BEARISH else marketType.NEUTRAL;

def R3;
def R2;
def R1;
def RR;
def PP;
def SS;
def S1;
def S2;
def S3;

if !IsNaN(close(period = timeFrameDay)[-1])
then {
    R1 = Double.NaN;
    R2 = Double.NaN;
    R3 = Double.NaN;
    PP = Double.NaN;
    S1 = Double.NaN;
    S2 = Double.NaN;
    S3 = Double.NaN;
} else {
    PP = (high(period = timeFrameDay)[1] + low(period = timeFrameDay)[1] + close(period = timeFrameDay)[1]) / 3;
    R1 = 2 * PP - low(period = timeFrameDay)[1];
    R2 = PP + high(period = timeFrameDay)[1] - low(period = timeFrameDay)[1];
    R3 = R2 + high(period = timeFrameDay)[1] - low(period = timeFrameDay)[1];
    S1 = 2 * PP - high(period = timeFrameDay)[1];
    S2 = PP - high(period = timeFrameDay)[1] + low(period = timeFrameDay)[1];
    S3 = S2 - high(period = timeFrameDay)[1] + low(period = timeFrameDay)[1];
}

RR = if (marketType == marketType.BEARISH or marketType == marketType.NEUTRAL) then R1 else R2;
SS = if (marketType == marketType.BULLISH or marketType == marketType.NEUTRAL) then S1 else S2;


def bn = HighestAll(if open == open then BarNumber()-3  else double.nan);
def futurebar = 5;
def x = (!IsNaN(close[futurebar]) and IsNaN(close[futurebar - 1]));


def RRBub = if barnumber() < bn then double.nan else  Highestall(if (isnan(close[-1]) and !IsNaN(close)) and RR > close * .99 and RR < close * 1.01 then 1 else double.nan);

DefineGlobalColor("D”, CreateColor(133, 163, 104));
addchartbubble(rrbub,RR, "RR", GlobalColor("D"));
 
Last edited:
Hi All,

I'd like to put the RR chart bubbles to the right of the current bar a few bars into the future. Is this possible to do? Currently the RR bubble on the current candle is hindering my view. If its not possible to push the bubbles to the right, am I able to eliminate the bubble on each current bar so that my view isn't hindered? I've searched existing studies but haven't been able to find the right code. Thanks in advance!


Code:
input marketThreshold = 0.0025;
input timeFrameDay = {default DAY};
input applyPersonsLevelsFilter = yes;

assert(marketThreshold >= 0, "'market threshold' must not be negative: " + marketThreshold);

def marketType = {default DISABLED, NEUTRAL, BEARISH, BULLISH};

def PP2 = high(period = timeFrameDay)[2] + low(period = timeFrameDay)[2] + close(period = timeFrameDay)[2];

marketType = if !applyPersonsLevelsFilter then marketType.DISABLED else
if PP2[-1] > (PP2[-1] + PP2 + PP2[1]) / 3 + marketThreshold then marketType.BULLISH else
if PP2[-1] < (PP2[-1] + PP2 + PP2[1]) / 3 - marketThreshold then marketType.BEARISH else marketType.NEUTRAL;

def R3;
def R2;
def R1;
def RR;
def PP;
def SS;
def S1;
def S2;
def S3;

if !IsNaN(close(period = timeFrameDay)[-1])
then {
    R1 = Double.NaN;
    R2 = Double.NaN;
    R3 = Double.NaN;
    PP = Double.NaN;
    S1 = Double.NaN;
    S2 = Double.NaN;
    S3 = Double.NaN;
} else {
    PP = (high(period = timeFrameDay)[1] + low(period = timeFrameDay)[1] + close(period = timeFrameDay)[1]) / 3;
    R1 = 2 * PP - low(period = timeFrameDay)[1];
    R2 = PP + high(period = timeFrameDay)[1] - low(period = timeFrameDay)[1];
    R3 = R2 + high(period = timeFrameDay)[1] - low(period = timeFrameDay)[1];
    S1 = 2 * PP - high(period = timeFrameDay)[1];
    S2 = PP - high(period = timeFrameDay)[1] + low(period = timeFrameDay)[1];
    S3 = S2 - high(period = timeFrameDay)[1] + low(period = timeFrameDay)[1];
}

RR = if (marketType == marketType.BEARISH or marketType == marketType.NEUTRAL) then R1 else R2;
SS = if (marketType == marketType.BULLISH or marketType == marketType.NEUTRAL) then S1 else S2;


def bn = HighestAll(if open == open then BarNumber()-3  else double.nan);
def futurebar = 5;
def x = (!IsNaN(close[futurebar]) and IsNaN(close[futurebar - 1]));


def RRBub = if barnumber() < bn then double.nan else  Highestall(if (isnan(close[-1]) and !IsNaN(close)) and RR > close * .99 and RR < close * 1.01 then 1 else double.nan);

DefineGlobalColor("D”, CreateColor(133, 163, 104));
addchartbubble(rrbub,RR, "RR", GlobalColor("D"));

This is a bubble mover code that should help by replacing your bubble code with the following. The input bubblemover will move the bubble sideways right/left (+/-) the number of bars/spaces input. This portion of the code (IsNaN(RRBub[b1]) and !IsNaN(RRBub) limits the bubbles to just one bubble.
Ruby:
input bubblemover = 5;
def b  = bubblemover;
def b1 = b + 1;

DefineGlobalColor("D, CreateColor(133, 163, 104));
AddChartBubble(IsNaN(RRBub[b1]) and !IsNaN(RRBub[b]), RR[b], "RR", GlobalColor("D"));
 
How can you offset bubbles higher then the high of bar and lower then the low of bar so doesnt hide the candle ?

thank you for info, but im looking to offset the bubbles up and down, not sideways

can anyone give an example of format to add higher price to chart bubble please
 
How can you offset bubbles higher then the high of bar and lower then the low of bar so doesnt hide the candle ?

thank you for info, but im looking to offset the bubbles up and down, not sideways

can anyone give an example of format to add higher price to chart bubble please
Your question is how to define higher then the high of bar and lower then the low of bar for the location of the AddChartBubble so it doesn't hide the candle?

Answer:
You can add an offset to your location. IE: 1% higher then the high of bar or 1% lower then the low of bar
written as: low - (low*.01) or high + (high*.01)

So this script:
Rich (BB code):
AddChartBubble(Low, low-(low*.01), close, color.light_gray);
would produce this:
DqjfMfX.png
 
hi guys, i have an indicator that plot previous day's high/ low and overnight high/ low on the chart. its chart bubbles on these lines keep moving along with the current time.
so my problem is that when price goes close to one of these lines it is engulfed by the bubbles. so is there a way to move these bubbles to either a few bars to the left or right of the current bar? thanks
 
Last edited:

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
323 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