BubbleMover Code Snippet for ThinkOrSwim

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

Without your code, here is an example that has a bubblemover input that you can use to move the bubbles left/right.

Capture.jpg
Ruby:
input time        = {default Day, Week, Month, Year};
input displace    = 1;
input bubblemover = 11;
def n  = bubblemover;
def n1 = n + 1;
input rthbegin = 0930;
input rthend   = 1600;
def pastOpen   = If((SecondsTillTime(rthbegin) > 0), 0, 1);
def pastClose  = If((SecondsTillTime(rthend) > 0), 0, 1);
def marketOpen = If(pastOpen and !pastClose, 1, 0);
def firstBar   = If (GetDay()[1] != GetDay(), GetDay() - 1, 0);
def h = high;
def l = low;
def o = open;
def c = close;
rec rthHigh = If(h > rthHigh[1] and marketOpen, h, If(marketOpen and !firstBar, rthHigh[1], h));
rec rthLow  = If(l < rthLow[1] and marketOpen, l, If(marketOpen and rthLow[1] > 0 and !firstBar, rthLow[1], l));

plot PH  = high(period = time)[displace];
plot PL  = low(period = time)[displace];
plot PC  = close(period = time)[displace];
plot TO  = open(period = time);
plot PP  = PivotPoints().pp;
plot HD  = if marketOpen then rthHigh else Double.NaN;
plot LD  = if marketOpen then rthLow  else Double.NaN;
plot MD  = (rthHigh + rthLow) / 2;
input showhlcloud = no;
AddCloud(if showhlcloud then  h + 10  else Double.NaN, HD, Color.DARK_GREEN);
AddCloud(if showhlcloud then LD else Double.NaN, l - 10  , Color.DARK_RED);

PH.SetDefaultColor(Color.GREEN);
PH.SetStyle(Curve.MEDIUM_DASH);
PH.SetLineWeight(2);
PH.HideBubble();

PL.SetDefaultColor(Color.RED);
PL.SetStyle(Curve.MEDIUM_DASH);
PL.SetLineWeight(2);
PL.HideBubble();

PC.SetDefaultColor(Color.YELLOW);
PC.SetStyle(Curve.LONG_DASH);
PC.SetLineWeight(2);
PC.HideBubble();

TO.SetDefaultColor(Color.WHITE);
TO.SetStyle(Curve.LONG_DASH);
TO.SetLineWeight(2);
TO.HideBubble();

PP.SetDefaultColor(Color.WHITE);
PP.SetStyle(Curve.SHORT_DASH);
PP.SetLineWeight(2);
PP.HideBubble();

HD.SetDefaultColor(Color.GREEN);
HD.SetStyle(Curve.SHORT_DASH);
HD.SetLineWeight(2);
HD.HideBubble();

LD.SetDefaultColor(Color.RED);
LD.SetStyle(Curve.SHORT_DASH);
LD.SetLineWeight(2);
LD.HideBubble();

MD.SetDefaultColor(Color.MAGENTA);
MD.SetStyle(Curve.POINTS);
MD.SetLineWeight(2);
MD.HideBubble();

input showbubbles = yes;
def StartPlot = if showbubbles == yes then (IsNaN(c[n]) and !IsNaN(c[n1])) else Double.NaN;

AddChartBubble(StartPlot,  Round(PH[n1], 2), "PH-" + Round(PH[n1], 2), Color.GREEN, yes);
AddChartBubble(StartPlot,  Round(PL[n1], 2), "PL-" + Round(PL[n1], 2), Color.RED, yes);
AddChartBubble(StartPlot,  Round(TO[n1], 2), "TO-" + Round(TO[n1], 2), Color.WHITE, yes);
AddChartBubble(StartPlot,  Round(PP[n1], 2), "PP-" + Round(PP[n1], 2), Color.WHITE, yes);
AddChartBubble(StartPlot,  Round(PC[n1], 2), "PC-" + Round(PC[n1], 2), Color.YELLOW, yes);
AddChartBubble(StartPlot,  Round(HD[n1], 2), "HD-" + Round(HD[n1], 2), Color.GREEN, yes);
AddChartBubble(StartPlot,  Round(LD[n1], 2), "LD-" + Round(LD[n1], 2), Color.RED, no);
AddChartBubble(StartPlot,  Round(MD[n1], 2), "MD-" + Round(MD[n1], 2), Color.MAGENTA, no);

def hdcloud   = if IsNaN(c)
                then hdcloud[1]
                else HD;
plot hdcloud1 = if !IsNaN(c)
                then Double.NaN
                else hdcloud;
def phcloud   = if IsNaN(c)
                then phcloud[1]
                else PH;
plot phcloudl = if !IsNaN(c[12])
                then Double.NaN
                else phcloud;
def plcloud   = if IsNaN(c)
                then plcloud[1]
                else PL;
plot plcloudl = if !IsNaN(c[12])
                then Double.NaN
                else plcloud;
def ldcloud   = if IsNaN(c)
                then ldcloud[1]
                else LD;
plot ldcloudl = if !IsNaN(c[12])
                then Double.NaN
                else ldcloud;
def pccloud   = if IsNaN(c)
                then pccloud[1]
                else PC;
plot pccloudl = if !IsNaN(c[12])
                then Double.NaN
                else pccloud;
AddCloud(hdcloud1, phcloudl, Color.GREEN, Color.GREEN);
AddCloud(phcloudl, pccloudl, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(pccloudl, plcloudl, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(plcloudl, ldcloudl, Color.RED, Color.RED);
 
  • Like
Reactions: bik

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

I'd like to have the RSI showed on the right side of the chart where the price is. I have the RSI as bubble on top of the last candle but it blocks some view. THanks.
 
I'd like to have the RSI showed on the right side of the chart where the price is. I have the RSI as bubble on top of the last candle but it blocks some view. THanks.

You can move the bubble in this code sideways to where you want it.

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#

declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.Color("OverBought") else if RSI < over_Sold then RSI.Color("OverSold") else RSI.Color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

#Bubble
input showbubble  = yes;
input bubblemover = 3;
def bm  = bubblemover;
def bm1 = bm + 1;
addchartBubble(showbubble and isnan(close[bm]) and !isnan(close[bm1]), rsi[bm1],
               rsi[bm1], color.white);
 
How do I make the bubbles more off to the right in the B3_HILO_V3 study. Essentially I feel the bubbles are to on-top of the price action and difficult to read, id like to retain the bubbles but push them to the right a bit? Thanks for your help as always, you are a god around here.

Code:
# Simply plots a line at the latest printing of a high or low for each day (or agg of your choosing).
# Note that your aggs chosen in this study must be a longer time frame than your chart's agg for this to study to plot.
#
# Version 2 adds the 50% of 1d and 2d ranges.
# Version 3 adds Closeweighting and made it optional.
# Version 3.1 cleans the code up and straightens out features (housekeeping).
##
DECLARE UPPER;
INPUT AGG = AGgregationPeriod.DAY;
INPUT BUBBLES = NO;
INPUT LABELS = NO;
INPUT CLOSEWEIGHTTODAY = NO;
INPUT CLOSEWEIGHTYEST = yes;
INPUT CLOSEWEIGHTTWODAY = yes;
PLOT HI = HIGH(PERIOD = AGG);
PLOT LO = LOW(PERIOD = AGG);
PLOT YHI = HIGH(PERIOD = AGG)[1];
PLOT YLO = LOW(PERIOD = AGG)[1];
PLOT FIFTYPCT = if cloSEWEIGHTTODAY then (hi + lo + close(period = agg)) / 3 else (HI + LO) / 2;
PLOT YESTERDAYFTYPCT = if cloSEWEIGHTYEST then (yhi + ylo + close(period = agg)[1]) / 3 else (YHI + YLO) / 2;
DEF WHICHHI = IF YHI > YHI[1] THEN YHI ELSE YHI[1];
DEF WHICHLO = IF YLO < YLO[1] THEN YLO ELSE YLO[1];
DEF TODAY = if (GetDay() == GetLastDay()) or (GetlastDay() - 1 == getday()) then yes else no;
DEF BUBBLESPOT = if IsNaN(open[-1]) && !IsNaN(open) then (BarNumber() - 1) else DOUBLE.NAN;
PLOT FIFTYPCTTWODAY = if ClOSEWEIGHTTWODAY then (WHICHHI + WHICHLO + close(period = AGG)[1]) / 3 else (WHICHHI + WHICHLO) / 2;
HI.SETLINEWeight(2);
LO.SETLINEWeight(2);
HI.SETDefaultColor(CREATECOlor(166,130,166));
LO.SETDefaultColor(CREATECOlor(166,130,166));
YLO.SETDefaultColor(CREATECOlor(146,120,146));
YHI.SETDefaultColor(CREATECOlor(146,120,146));
FIFTYPCT.setDefaultColor(Color.GRAY);
FIFTYPCT.setpaintingStrategy(paintingStrategy.DASHES);
YESTERDAYFTYPCT.setDefaultColor(Color.Dark_GRAY);
YESTERDAYFTYPCT.setpaintingStrategy(paintingStrategy.SQUARES);
FIFTYPCTTWODAY.setDefaultColor(Color.GRAY);
FIFTYPCTTWODAY.setpaintingStrategy(paintingStrategy.TRIANGLES);
ADDLABEL(LABELS, "HI/50/LO=" + HI + "/ " + FIFTYPCT +"/ " + LO, CREATECOlor(166,130,166));
ADDLABEL(LABELS, "2D 50%=" + FIFTYPCTTWODAY, COLOR.GRAY);
ADDLABEL(LABELS, "YEST=" + YHI + "/ " + YESTERDAYFTYPCT + "/ " + YLO, CREATECOlor(146,120,146));

ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, HI, "HI",CREATECOlor(166,130,166), YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, LO, "LO",CREATECOlor(166,130,166), NO);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, YHI, "YEST HI",CREATECOlor(146,120,146), if close > YHI then NO else YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, YLO, "YEST LO",CREATECOlor(146,120,146), if close > YLO then NO else YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, FIFTYPCT, "TODAY 50%", COLOR.GRAY, IF CLOSE > FIFTYPCT THEN NO ELSE YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, YESTERDAYFTYPCT, "YEST 50%", COLOR.GRAY, IF CLOSE > YESTERDAYFTYPCT THEN NO ELSE YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, FIFTYPCTTWODAY, "2D 50%", COLOR.GRAY, IF CLOSE > FIFTYPCTTWODAY THEN NO ELSE YES);
 
Last edited by a moderator:
How do I make the bubbles more off to the right in the B3_HILO_V3 study. Essentially I feel the bubbles are to on-top of the price action and difficult to read, id like to retain the bubbles but push them to the right a bit? Thanks for your help as always, you are a god around here.

i didn't load this , but i assume you want bubbles after the last bar.

shapes can be placed after the last bar,
by creating a true/false formula, that checks,
if some previous bar had valid price data, and the bar after that one does not have valid price data.

this is true when on the bar that is 4 bars after the last bar
def x = !isNaN(close[4+1]) and isNaN(close[4]);

have to remember to read a previous valid bar for a price value, because there are no prices after the last bar.


here are a couple ways to place a bubble after the last bar
https://usethinkscript.com/threads/bubblemover-code-snippet-for-thinkorswim.9392/#post-85145

https://usethinkscript.com/threads/display-bubble-on-the-right-edge.3037/#post-66620
 
Last edited:
i didn't load this , but i assume you want bubbles after the last bar.

shapes can be placed after the last bar,
by creating a true/false formula, that checks,
if some previous bar had valid price data, and the bar after that one does not have valid price data.

this is true when on the bar that is 4 bars after the last bar
def x = !isNaN(close[4+1]) and isNaN(close[4]);

have to remember to read a previous valid bar for a price value, because there are no prices after the last bar.


here are a couple ways to place a bubble after the last bar
https://usethinkscript.com/threads/bubblemover-code-snippet-for-thinkorswim.9392/#post-85145

https://usethinkscript.com/threads/display-bubble-on-the-right-edge.3037/#post-66620
Appreciate the help and relocation of my question. But I have the bubbles I just want to move them to the right so they arent on top of current candle. Does that make sense?

 
Appreciate the help and relocation of my question. But I have the bubbles I just want to move them to the right so they arent on top of current candle. Does that make sense?

merryday tends to move posts around, with others similar to it.

'after the last bar' , tends to mean,
moving shapes to the right. what i posted will help you do what you want to do.
 
merryday tends to move posts around, with others similar to it.

'after the last bar' , tends to mean,
moving shapes to the right. what i posted will help you do what you want to do.
well perfect, I apologize, I thought you misunderstood. I will take a look at your links.

Thank you
 
well perfect, I apologize, I thought you misunderstood. I will take a look at your links.

Thank you

you're welcome. take a look , copy 1 or both codes and try them.

thanks for questioning my post. i looked it over and found my code ( the 2nd link in post#2 ) was off by 1 bar.
i updated the code in my other post and and simplified it. i added a big bubble with words describing what it is doing.
and i added an image of it, so people will know right away what the code will do.
 
Last edited:
Hmm well I appreciate the help, guess im not much of a coder... Usually I can figure it out, but this has me stumped. I found the second post you sent more helpful, with the following line of code:

input bubblemover = 5;
def b = bubblemover;
def b1 = b + 1;

DefineGlobalColor("D”, CreateColor(133, 163, 104));
AddChartBubble(IsNaN(RRBub[b1]) and !IsNaN(RRBub), RR, "RR", GlobalColor("D"));



I am still having issues on where to post that line of code. I realize the last sentence is two seperate codes, so it wasnt that, that tripped me up. I placed it at the beginning of my code just like I saw others did in that thread. But no dice. I played around with the addchartbubble code, I just cant figure out where to put it. Can you just let me know after what would I add something like this? If it helps to refer to the picture above - so that you know what I am after, I just think the several instances of "bubblespot" may be throwing it off? There should be 7 bubbles in all, and all shifted to the right by 11 spaces (I say 11 because I saw a user had 11 inputted in his/hers and it looked about right. Thanks again for all your help.


Code:
DECLARE UPPER;
input bubblemover = 11;
def n  = bubblemover;
def n1 = n + 1;
INPUT AGG = AGgregationPeriod.DAY;
INPUT BUBBLES = NO;
INPUT LABELS = NO;
INPUT CLOSEWEIGHTTODAY = NO;
INPUT CLOSEWEIGHTYEST = yes;
INPUT CLOSEWEIGHTTWODAY = yes;
PLOT HI = HIGH(PERIOD = AGG);
PLOT LO = LOW(PERIOD = AGG);
PLOT YHI = HIGH(PERIOD = AGG)[1];
PLOT YLO = LOW(PERIOD = AGG)[1];
PLOT FIFTYPCT = if cloSEWEIGHTTODAY then (hi + lo + close(period = agg)) / 3 else (HI + LO) / 2;
PLOT YESTERDAYFTYPCT = if cloSEWEIGHTYEST then (yhi + ylo + close(period = agg)[1]) / 3 else (YHI + YLO) / 2;
DEF WHICHHI = IF YHI > YHI[1] THEN YHI ELSE YHI[1];
DEF WHICHLO = IF YLO < YLO[1] THEN YLO ELSE YLO[1];
DEF TODAY = if (GetDay() == GetLastDay()) or (GetlastDay() - 1 == getday()) then yes else no;
DEF BUBBLESPOT = if IsNaN(open[-1]) && !IsNaN(open) then (BarNumber() - 1) else DOUBLE.NAN;
PLOT FIFTYPCTTWODAY = if ClOSEWEIGHTTWODAY then (WHICHHI + WHICHLO + close(period = AGG)[1]) / 3 else (WHICHHI + WHICHLO) / 2;
HI.SETLINEWeight(2);
LO.SETLINEWeight(2);
HI.SETDefaultColor(CREATECOlor(166,130,166));
LO.SETDefaultColor(CREATECOlor(166,130,166));
YLO.SETDefaultColor(CREATECOlor(146,120,146));
YHI.SETDefaultColor(CREATECOlor(146,120,146));
FIFTYPCT.setDefaultColor(Color.GRAY);
FIFTYPCT.setpaintingStrategy(paintingStrategy.DASHES);
YESTERDAYFTYPCT.setDefaultColor(Color.Dark_GRAY);
YESTERDAYFTYPCT.setpaintingStrategy(paintingStrategy.SQUARES);
FIFTYPCTTWODAY.setDefaultColor(Color.GRAY);
FIFTYPCTTWODAY.setpaintingStrategy(paintingStrategy.TRIANGLES);
ADDLABEL(LABELS, "HI/50/LO=" + HI + "/ " + FIFTYPCT +"/ " + LO, CREATECOlor(166,130,166));
ADDLABEL(LABELS, "2D 50%=" + FIFTYPCTTWODAY, COLOR.GRAY);
ADDLABEL(LABELS, "YEST=" + YHI + "/ " + YESTERDAYFTYPCT + "/ " + YLO, CREATECOlor(146,120,146));

ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, HI, "HI",CREATECOlor(166,130,166), YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, LO, "LO",CREATECOlor(166,130,166), NO);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, YHI, "YEST HI",CREATECOlor(146,120,146), if close > YHI then NO else YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, YLO, "YEST LO",CREATECOlor(146,120,146), if close > YLO then NO else YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, FIFTYPCT, "TODAY 50%", COLOR.GRAY, IF CLOSE > FIFTYPCT THEN NO ELSE YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, YESTERDAYFTYPCT, "YEST 50%", COLOR.GRAY, IF CLOSE > YESTERDAYFTYPCT THEN NO ELSE YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND BUBBLESPOT, FIFTYPCTTWODAY, "2D 50%", COLOR.GRAY, IF CLOSE > FIFTYPCTTWODAY THEN NO ELSE YES);
 
Bubbles to the far right

Code:
# Simply plots a line at the latest printing of a high or low for each day (or agg of your choosing).
# Note that your aggs chosen in this study must be a longer time frame than your chart's agg for this to study to plot.
#
# Version 2 adds the 50% of 1d and 2d ranges.
# Version 3 adds Closeweighting and made it optional.
# Version 3.1 cleans the code up and straightens out features (housekeeping).
##
DECLARE UPPER;
INPUT AGG = AGgregationPeriod.DAY;
INPUT BUBBLES = NO;
INPUT LABELS = NO;
INPUT CLOSEWEIGHTTODAY = NO;
INPUT CLOSEWEIGHTYEST = yes;
INPUT CLOSEWEIGHTTWODAY = yes;
PLOT HI = HIGH(PERIOD = AGG);
PLOT LO = LOW(PERIOD = AGG);
PLOT YHI = HIGH(PERIOD = AGG)[1];
PLOT YLO = LOW(PERIOD = AGG)[1];
PLOT FIFTYPCT = if cloSEWEIGHTTODAY then (hi + lo + close(period = agg)) / 3 else (HI + LO) / 2;
PLOT YESTERDAYFTYPCT = if cloSEWEIGHTYEST then (yhi + ylo + close(period = agg)[1]) / 3 else (YHI + YLO) / 2;
DEF WHICHHI = IF YHI > YHI[1] THEN YHI ELSE YHI[1];
DEF WHICHLO = IF YLO < YLO[1] THEN YLO ELSE YLO[1];
DEF TODAY = if (GetDay() == GetLastDay()) or (GetlastDay() - 1 == getday()) then yes else no;
DEF BUBBLESPOT = if IsNaN(open[-1]) && !IsNaN(open) then (BarNumber() - 1) else DOUBLE.NAN;
PLOT FIFTYPCTTWODAY = if ClOSEWEIGHTTWODAY then (WHICHHI + WHICHLO + close(period = AGG)[1]) / 3 else (WHICHHI + WHICHLO) / 2;
HI.SETLINEWeight(2);
LO.SETLINEWeight(2);
HI.SETDefaultColor(CREATECOlor(166,130,166));
LO.SETDefaultColor(CREATECOlor(166,130,166));
YLO.SETDefaultColor(CREATECOlor(146,120,146));
YHI.SETDefaultColor(CREATECOlor(146,120,146));
FIFTYPCT.setDefaultColor(Color.GRAY);
FIFTYPCT.setpaintingStrategy(paintingStrategy.DASHES);
YESTERDAYFTYPCT.setDefaultColor(Color.Dark_GRAY);
YESTERDAYFTYPCT.setpaintingStrategy(paintingStrategy.SQUARES);
FIFTYPCTTWODAY.setDefaultColor(Color.GRAY);
FIFTYPCTTWODAY.setpaintingStrategy(paintingStrategy.TRIANGLES);
ADDLABEL(LABELS, "HI/50/LO=" + HI + "/ " + FIFTYPCT +"/ " + LO, CREATECOlor(166,130,166));
ADDLABEL(LABELS, "2D 50%=" + FIFTYPCTTWODAY, COLOR.GRAY);
ADDLABEL(LABELS, "YEST=" + YHI + "/ " + YESTERDAYFTYPCT + "/ " + YLO, CREATECOlor(146,120,146));

def x = BarNumber();

ADDCHARTBUBBLE(BUBBLES AND TODAY AND x == HighestAll(x), HI, "HI",CREATECOlor(166,130,166), YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND x == HighestAll(x), LO, "LO",CREATECOlor(166,130,166), NO);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND x == HighestAll(x), YHI, "YEST HI",CREATECOlor(146,120,146), if close > YHI then NO else YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND x == HighestAll(x), YLO, "YEST LO",CREATECOlor(146,120,146), if close > YLO then NO else YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND x == HighestAll(x), FIFTYPCT, "TODAY 50%", COLOR.GRAY, IF CLOSE > FIFTYPCT THEN NO ELSE YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND x == HighestAll(x), YESTERDAYFTYPCT, "YEST 50%", COLOR.GRAY, IF CLOSE > YESTERDAYFTYPCT THEN NO ELSE YES);
ADDCHARTBUBBLE(BUBBLES AND TODAY AND x == HighestAll(x), FIFTYPCTTWODAY, "2D 50%", COLOR.GRAY, IF CLOSE > FIFTYPCTTWODAY THEN NO ELSE YES);
 
You can move the bubble in this code sideways to where you want it.
Hi,
This is the code and have and it works:

plot rsi = reference RSI (14);



AddChartBubble(!IsNaN(close) and IsNaN(close [-1] ) , close , Round (rsi, 1) + "" , Color.WHITE);

However the bubble disappears when replacing the above AddChartBubble with ;

input showbubble = yes;
input bubblemover = 3;
def bm = bubblemover;
def bm1 = bm + 1;
addchartBubble(showbubble and isnan(close[bm]) and !isnan(close[bm1]), rsi[bm1],
rsi[bm1], color.white);

Thanks.
 
Can anyone edit this script, to improve the visibility of myr Thinkorswim chart?

I think if the buy-sell bubble & price trigger is positioned to the left of the movinging candle, rather than to the right, that will be better.

Why? Because as-is I can't easily see the candles that appear one-after-another as time marches on. And if the bubble and appear to the left then the candle overlap will at least be over historical candles and on the realtime candles.

Here's the script which puts the buy or sell bubble to the right side of the trigger point:

# SuperTrend
# Mobius
# Chat Room Request
# 11.20.2019 tomsk Enhanced and adjusted bubbles with coloring and description tag

input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
input n = 0;
def n1 = n + 1;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and close < ST
then Color.RED
else if PaintBars and close > ST
then Color.GREEN
else Color.CURRENT);

AddChartBubble(close[n] crosses below ST[n], low[n+1] + TickSize() * n, "Sell @ " + low[n1], color.Cyan, yes);
AddChartBubble(close[n] crosses above ST[n], high[n+1] - TickSize() * n, "Buy @ " + high[n1], color.Yellow, no);

# End Code SuperTrend


===== THANK YOU MOBIUS & TOMSK!!! =====

Here's a picture of my Thinkorswim trading window that shows the problem: When a buy or sell bubble appears to the right of the moving price -- it overlaps several new candles that are the most import to watch if you are daytrading. So if the above code can be edited so that these bubbles can appear to the left, that should improve this script:

 
Last edited:
Can anyone edit this script to remove several of the time based scanner bubbles? ...So that I see only two rows.

* I would like to see a 1-minute scan-row of bubbles on top if possible.

* I would like to see a second row of 5-minute scan-row of bubbles on the bottom.

* Please get rid of the 10, 15, 30 and 60 minute bubbles. I don't need or want these for day trading.

Note: Currently there is no 1Min-Scan-Bubble-Row. If this is for technical reasons, please leave it out and only show one row based on a 5Min-Scan-Bubble.

Also, having so many rows make it hard to see a smaller sized chart, because there are too many rows and they get overlapped when you reduce the size of the chart.

Here's the script that Mobius created:

# SuperTrend Multiple Time Frames
# Mobius
# V03.01.2016

# I pulled this study down from MyTrade for a reason. It wasn't
# plotting correctly with the multiple aggregations. And like
# all studies with secondary aggregations it tends to replot the
# higher ones. I decided to think about it some more and this is
# where I am with the ST MTF study now.
#
# It's still squirrely and blinks a lot. Using declare Once_Per_Bar
# does some bad things to it. I was considering making intra
# aggregation higher time frames. A pain to do but it gives more
# control over how it plots.
#
# Row 6 is supposed to be the output for all aggregations and the
# signal line. After hours when data isn't moving it's steady and
# has good signals. But since it's after hours, totally useless
# for any intraday trading.

declare lower;

input agg1 = AggregationPeriod.Five_Min;
input agg2 = AggregationPeriod.Ten_Min;
input agg3 = AggregationPeriod.Fifteen_Min;
input agg4 = AggregationPeriod.Thirty_Min;
input agg5 = AggregationPeriod.Hour;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;

script ST{
input agg = AggregationPeriod.Five_Min;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
def Fh = FundamentalType.High;
def Fl = FundamentalType.Low;
def Fc = FundamentalType.Close;
def Fhl2 = FundamentalType.HL2;
def h = Fundamental(Fh, period = agg);
def l = Fundamental(Fl, period = agg);
def c = Fundamental(Fc, period = agg);
def hl = Fundamental(Fhl2, period = agg);
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);
def UP = hl + (AtrMult * ATR);
def DN = hl + (-AtrMult * ATR);
def S = if c < S[1]
then Round(UP / tickSize(), 0) * tickSize()
else Round(DN / tickSize(), 0) * tickSize();
plot ST = if c > S then 1 else 0;
}
def cl = close;
def x = isNaN(cl[2]) and !isNaN(cl[3]);
def FirstAgg = ST(agg = agg1, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot FirstAggPlot = if isNaN(cl)
then double.nan
else 1;
FirstAggPlot.SetStyle(Curve.Points);
FirstAggPlot.SetLineWeight(3);
FirstAggPlot.AssignValueColor(if FirstAgg == 1
then color.green
else color.red);
AddChartBubble(x, 1, (agg1/1000/60) + " min", color.white, yes);
def SecondAgg = ST(agg = agg2, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot SecondAggPlot = if isNaN(cl)
then double.nan
else 2;
SecondAggPlot.SetStyle(Curve.Points);
SecondAggPlot.SetLineWeight(3);
SecondAggPlot.AssignValueColor(if SecondAgg == 1
then color.green
else color.red);
AddChartBubble(x, 2, (agg2/1000/60) + " min", color.white, yes);
def ThirdAgg = ST(agg = agg3, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot ThirdAggPlot = if isNaN(cl)
then double.nan
else 3;
ThirdAggPlot.SetStyle(Curve.Points);
ThirdAggPlot.SetLineWeight(3);
ThirdAggPlot.AssignValueColor(if ThirdAgg == 1
then color.green
else color.red);
AddChartBubble(x, 3, (agg3/1000/60) + " min", color.white, yes);
def FourthAgg = ST(agg = agg4, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot FourthAggPlot = if isNaN(cl)
then double.nan
else 4;
FourthAggPlot.SetStyle(Curve.Points);
FourthAggPlot.SetLineWeight(3);
FourthAggPlot.AssignValueColor(if FourthAgg == 1
then color.green
else color.red);
AddChartBubble(x, 4, (agg4/1000/60) + " min", color.white, yes);
def FifthAgg = ST(agg = agg5, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot FifthAggPlot = if isNaN(cl)
then double.nan
else 5;
FifthAggPlot.SetStyle(Curve.Points);
FifthAggPlot.SetLineWeight(3);
FifthAggPlot.AssignValueColor(if FifthAgg == 1
then color.green
else color.red);
AddChartBubble(x, 5, (agg5/1000/60)+ " min", color.white, yes);
plot Six = if isNaN(cl)
then double.nan
else 6;
Six.SetStyle(Curve.Points);
Six.SetLineWeight(3);
Six.AssignValueColor(if FirstAgg and
SecondAgg and
ThirdAgg and
FourthAgg and
FifthAgg
then color.green
else if !FirstAgg and
!SecondAgg and
!ThirdAgg and
!FourthAgg and
!FifthAgg
then color.red
else color.black);
# End Code ST MTF

 
Last edited:
I don't believe bubbles can be moved and have them appear as you would like, however, the following will allow you to turn them on and off so you can see the chart when necessary.


C++:
# SuperTrend
# Mobius
# Chat Room Request
# 11.20.2019 tomsk Enhanced and adjusted bubbles with coloring and description tag

input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
input n = 0;
input showBubbles = yes;
def n1 = n + 1;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and close < ST
then Color.RED
else if PaintBars and close > ST
then Color.GREEN
else Color.CURRENT);

AddChartBubble(showBubbles and close[n] crosses below ST[n], low[n+1] + TickSize() * n, "Sell @ " + low[n1], color.Cyan, yes);
AddChartBubble(showBubbles and close[n] crosses above ST[n], high[n+1] - TickSize() * n, "Buy @ " + high[n1], color.Yellow, no);

# End Code SuperTrend
 
Thanks JoeDV.

I have not yet tested your script, but to your answer: "I don't believe bubbles can be moved and have them appear as you would like..." on the left...

However, I have to believe there is a way, because nothing happens by default; or the code has some "organic forman," then I would think there should be a way to manipulte or add code that forces a left-justified bubble.

Note: I don't code; not since I took a Fortran class back in '78. I'm just thinking logically.

For example, might a line be added like this...

if x=bubble then display_left

So with all respect, and appreciation, I hope you think of a way to accomplish this code improvement or that someone else can come up with a solution.
 
Last edited:
So with all respect, and appreciation, I hope you think of a way to accomplish this code improvement or that someone else can come up with a solution.

I choose my words for a reason, can you move the bubbles, yes.. Will it look the way you want, in my opinion, no. If you search the forum you will find several posts on how to shift the bubbles around. It's not as simple as you're explaining however. Thinkscript is just that, a scripting language not a full-blown development language as many of us wish.

For the record, I started off with Fortran as well.
 
I have to believe there is a way, because nothing happens by default; or the code has some "organic forman," then I would think there should be a way to manipulte or add code that forces a left-justified bubble.

As @JoeDV stated, the ToS app does not provide for custom placement of chart bubbles.
As @JoeDV stated there is a bubble mover work-around however it might not yield the results you are looking for.
read more about bubble mover script:
https://usethinkscript.com/threads/bubblemover-code-snippet-for-thinkorswim.9392/
read more about how to search the forum for more examples:
https://usethinkscript.com/threads/search-the-forum.12626/
 
Thanks to you both! I can now see this subject has been discussed recentely, but I'm not smart enough to piece the code together to deliver a working result.

I did find few examples of what I (we) are talking about, but I have not added these edits, but I will play around with these snippets taken from the threads mentioned by MerryDay in other threads and by other forum members. For example:

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), RR, "RR", GlobalColor("D"));

and/or

You can move the bubble in this code sideways to where you want it. ...Hi, This is the code and have and it works:

plot rsi = reference RSI (14);

and another member said: 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);

Of course, the odds I will be successful editigin and adding code successfully are 1 in a 1000. Maybe 1M. So if you guys want to play around with it, please keep us posted of your triumpths!
 
Last edited:
Personally, I'd change your sells to be at the high and buys at the low, then move them up and down by a set amount. That should push them out of the way as long as your signal is in the correct direction. The bubble's "arrow" will always point to the left so moving them sideways just makes them look like they're related to the wrong candle.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
236 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