BubbleMover Code Snippet for ThinkOrSwim

greco26

Active member
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:

SleepyZ

Well-known member
VIP
Lifetime
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"));
 

keithm

New member
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
 

MerryDay

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

bik

New member
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:

SleepyZ

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

leMan

New member
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.
 

SleepyZ

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

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