Bubble Move for Referenced Symbol with Value

Carl-not-Karl

Member
VIP
uTS has good posts/threads on the Bubble Mover issue but I was not able to find a solution for a referenced symbol with it's value included in the bubble.
I am looking for 3 Inputs to control viewing of the Bubble Mover and it's Horizontal and Vertical positions from the Edit Studies and Strategies window.

Edit: removed == Yes from AddChartBubble(Bubble == Yes

This is what I was able to create so far and am now seeking assistance on the movement problem:

Kv1cUdy.png


Code:
declare lower;

input Bubble      = No;
input bubbleMoveH = 0; # Move Horizontal
input bubbleMoveV = 0; # Move Vertical

def Symbol = close("SPY");

plot Sym = Symbol;

def Data = if IsNaN(close[-1]) then Sym else Double.NaN;

def bMH  = bubbleMoveH;
def bMH1 = bMH + 1;
def bMV  = bubbleMoveV;

AddChartBubble(Bubble and isNaN(close[-1]) and !isNaN(close),
 Data, "SPY " + Round(Data,2),
 Sym.TakeValueColor());
 
Last edited:
Solution
uTS has good posts/threads on the Bubble Mover issue but I was not able to find a solution for a referenced symbol with it's value included in the bubble.
I am looking for 3 Inputs to control viewing of the Bubble Mover and it's Horizontal and Vertical positions from the Edit Studies and Strategies window.

Edit: removed == Yes from AddChartBubble(Bubble == Yes

This is what I was able to create so far and am now seeking assistance on the movement problem: hal_bub


Code:
declare lower;

input Bubble      = No;
input bubbleMoveH = 0; # Move Horizontal
input bubbleMoveV = 0; # Move Vertical

def Symbol = close("SPY");

plot Sym = Symbol;

def Data = if IsNaN(close[-1]) then Sym...
uTS has good posts/threads on the Bubble Mover issue but I was not able to find a solution for a referenced symbol with it's value included in the bubble.
I am looking for 3 Inputs to control viewing of the Bubble Mover and it's Horizontal and Vertical positions from the Edit Studies and Strategies window.

Edit: removed == Yes from AddChartBubble(Bubble == Yes

This is what I was able to create so far and am now seeking assistance on the movement problem: hal_bub


Code:
declare lower;

input Bubble      = No;
input bubbleMoveH = 0; # Move Horizontal
input bubbleMoveV = 0; # Move Vertical

def Symbol = close("SPY");

plot Sym = Symbol;

def Data = if IsNaN(close[-1]) then Sym else Double.NaN;

def bMH  = bubbleMoveH;
def bMH1 = bMH + 1;
def bMV  = bubbleMoveV;

AddChartBubble(Bubble and isNaN(close[-1]) and !isNaN(close),
 Data, "SPY " + Round(Data,2),
 Sym.TakeValueColor());
hal_bubble

this allows user to move the bubble,
...before or after the last bar
...above or below the close of offset bar

on edit settings screen, there are 2 hints that describe the x and y inputs.

can change the reference symbol

Code:
#bubble_move_xy

#https://usethinkscript.com/threads/bubble-move-for-referenced-symbol-with-value.17249/

declare lower;

input Bubble = yes;
# ref last bar
input bubbleMoveH = -1;
#hint bubbleMoveH: Move bubble horizontally, a bar quantity. \n..positive numbers for a bar before the last bar.\n..negagive numbers for a bar after the last bar.
input bubbleMoveV = 0.0;
#hint bubbleMoveV: Move bubble Vertically, a dollar amount. \n..positive numbers move it up.\n..negagive numbers move it down.

input symbol = "SPY";
def Symbol_cls = close(symbol);

plot Sym = Symbol_cls;
sym.SetDefaultColor(Color.yellow);

def x = !IsNaN(close[(0+(-bubbleMoveH))]) and IsNaN(close[(-1+(-bubbleMoveH))]);
def clsy = if isnan(symbol_cls) then clsy[1] else symbol_cls;
def y = clsy + bubbleMoveV;

AddChartBubble(Bubble and x, y,
 symbol + " " + Round(y, 2),
 Sym.TakeValueColor());

addlabel(1, symbol, Sym.TakeValueColor());


#---------------------
input test_vert_line = no;
addverticalline(test_vert_line and x, "-");

input test_labels = yes;
addlabel(test_labels, bubbleMoveH + "  horz offset", color.yellow);
addlabel(test_labels, bubbleMovev + "  vertical offset", color.yellow);
#
 
Last edited:
Solution
Adding to halcyonguy's script I have modified the code to include green(up)/red(down) color to the line and bubble.
A gray extension line was included (modified from a previous halcyonguy script):
https://usethinkscript.com/threads/markos-stuck-on-comparison-chart.17202/#post-134514

The image shows SPY (once added they were dragged to upper chart) with 5 location variations compared against QQQ.
Moving the bubble into the future changes to ToS default color of cyan.
The lower chart is stand-alone SPY:

8DKX91D.png


If the code below should be enhanced/modified in any way please let me know as I am still learning thinkscript.

Code:
# https://usethinkscript.com/threads/bubble-move-for-referenced-symbol-with-value.17249/#post-134853
#bubble_move_xy
#https://usethinkscript.com/threads/bubble-move-for-referenced-symbol-with-value.17249/
#Carl_K December 2023: added green/red color to line and bubble, GRAY line extension

declare lower;

input Bubble = yes;
# ref last bar
input bubbleMoveH = 0;
#hint bubbleMoveH: Move bubble horizontally, a bar quantity.
# \n negagive numbers for a bar after the last bar.
# \n positive numbers for a bar before the last bar.
input bubbleMoveV = 0.0;
#hint bubbleMoveV: Move bubble Vertically, a dollar amount.
# \n negagive numbers move it down.
# \n positive numbers move it up.

input symbol = "SPY";
def Symbol_cls = close(symbol);

plot Sym = Symbol_cls;
Sym.DefineColor("Up", GetColor(6));
Sym.DefineColor("Down", GetColor(5));
Sym.AssignValueColor(if Sym > Sym[1] then Sym.Color("Up") else Sym.Color("Down"));
Sym.SetLineWeight(1);
Sym.SetStyle(1);
Sym.HideBubble();
Sym.HideTitle();

def x    = !IsNaN(close[(0+(bubbleMoveH))]) and IsNaN(close[(-1+(bubbleMoveH))]);
def clsy = if isnan(symbol_cls) then clsy[1] else symbol_cls;
def y    = clsy + bubbleMoveV;

AddChartBubble(Bubble and x, y,
 symbol + " " + Round(y, 2),
 Sym.TakeValueColor());

addlabel(1, symbol, Sym.TakeValueColor());


def k = 0;
def bubline = IsNaN(close[k + 0]) and !IsNaN(close[bubbleMoveH + 0]);
def w = if (bubble and !IsNaN(close[k]) and IsNaN(close[k - 1])) then Sym[k] else if bubline then w[1] else double.NaN;

plot zw = w;
zw.SetDefaultColor(Color.GRAY);
zw.SetLineWeight(1);


#---------------------
input test_vert_line = no;
addverticalline(test_vert_line and x, "-");

input test_labels = yes;
addlabel(test_labels, bubbleMoveH + "  horz offset", color.yellow);
addlabel(test_labels, bubbleMovev + "  vertical offset", color.yellow);
#
 
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
324 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