AddChartBubble on 10 EMA

Branch

Member
I would some to have a Bubble on my 10SMA. When the 10sma rise or fall the bubble rise and fall so that I can see it on my chart; not just the line but line and bubble.
 
@Branch Here is your study as requested

Code:
# SMA Chart Bubble
# tomsk
# 1.14.2020

plot sma = Average(close, 10);
def Data = HighestAll(if isNaN(close[-1]) then sma else Double.NaN);

AddchartBubble(isNaN(close[1]) and !isNaN(close[2]), data, "SMA(10) at \n" + Round(data,2), Color.Yellow);
# End SMA Chart Bubble
 
@tomsk - OMG you and BenTen are the masters. I have been up all night trying to transpose this code (see below) to do what you provided above.

QQ: That "\n" in your code (divide by) what does the "n" represent?

Code:
input barsBack = 0;
input price= close;

def vClose = close;
def nan = double.NaN;
def bn = BarNumber();
def month = GetMonth();
def monthDay = GetDayOfMonth(GetYYYYMMDD());
def currentBar = HighestAll(if  !IsNaN(price) then bn else Double.NaN);
def highestClose = HighestAll(if IsNaN(vClose[-1]) then vClose else nan);
plot hc = highestClose;
hc.SetPaintingStrategy(PaintingStrategy.DASHES);
hc.SetDefaultColor(Color.DARK_ORANGE);

# throws an error symbol at top left of chart when condition is false. click on the error symbol to view the error message
       # condition  , "text"   
assert(barsBack >= 0, "''bars back'' cannot be negative ");
    # variables


AddChartBubble(bn == currentBar - barsBack, price,
# This section for text
"Price " +  ( if    price == close  then  "$ "  else  if    price == open  then  "Open: $"   else  if    price == low    then  " Low: $"   else  if    price == high   then  " High: $"   else  if    price == OHLC4  then  " OHLC4 $" else  if    price == HLC3  then  " HLC3 $" else  " Value:  " )+ price,(

# this section for color
if    price == close  then  color.cyan  else  if    price == open  then  color.pink   else  if    price == low  then  color.yellow  else  if price == high then  Color.White
else  if    price == OHLC4 then  Color.Dark_Orange else  if    price == HLC3 then  Color.Magenta else  color.Plum), yes);
 
@tomsk - OMG you and BenTen are the masters.
I have been up all night trying to transpose this code (see below) to do what you provided above.
QQ: That "\n" in your code (divide by) what does the "n" represent?


Very observant, all the "\n" in my code above is to force a new line to be inserted at that point. Try removing that "\n" and see the effects of what the resulting output would looks like. This by the way only works on bubbles, you can't use this for labels.

Okay @tomsk one last favor. Can you add a horizontal line (left to right) for the SMA price bubble? After this, I believe I would have my set-up (system for trading) in place.


Per your request, here is a horizontal line plotted across the chart at the current value of the SMA(10)

Code:
# SMA Chart Bubble with Horizontal Line
# tomsk
# 1.14.2020

def sma = Average(close, 10);
def Data = HighestAll(if isNaN(close[-1]) then sma else Double.NaN);
plot hLine = HighestAll(if isNaN(close[-1]) then sma else Double.NaN);
AddchartBubble(isNaN(close[1]) and !isNaN(close[2]), data, "SMA(10) at \n" + Round(data,2), Color.Yellow);
# End SMA Chart Bubble
 
Thanks Tomsk I worked on it this early this morning and figured it out; I came up with this on the 20ma and 10ma: (Again thank you tomsk)

Code:
input barsBack = 0;
input price = close;
input length1 = 20;
input displace = 0;
input showBreakoutSignals = no;

#---------------------------------------------------------------------
plot MA1 = Average(price[-displace], length1);

#---------------------------------------------------------------------
plot UpSignal1 = price crosses above MA1;
plot DownSignal1 = price crosses below MA1;

# MovingAverage--------------------------------------------------------------------
UpSignal1.SetHiding(!showBreakoutSignals);
DownSignal1.SetHiding(!showBreakoutSignals);

MA1.SetDefaultColor(GetColor(1));

def Data1 = HighestAll(if IsNaN(close[-1]) then MA1 else Double.NaN);

AddChartBubble(IsNaN(close[1]) and !IsNaN(close[2]), Data1, "20 Moving Avg \n" , Color.YELLOW);

#----------------------------------------------------------------------------------------------------
def nan = double.NaN;
def bn = BarNumber();
def currentBar = HighestAll(if  !IsNaN(price) then bn else Double.NaN);
def MA1Close = HighestAll(if IsNaN(close[-1]) then close else nan);
plot DATA = DATA1;
 
Last edited:
Hello,

I am trying to create a condition where bubbles are displayed if one of these two things happen:
1) yellow bubble = if ema9 is over ema20
2) green bubble = if ema20 is over sma50

Here's the code for the bubbles that I created.
AddChartBubble(ema9 > ema20, low, "9>20", Color.yellow, no);
AddChartBubble(ema20 > sma50, low, "20>50", Color.green, no);

What I'm trying to do is build it in a way that the system first checks to see if the 20 is over the 50. If so, it displays the green bubble...if the 20 is NOT over the 50, it checks to see if the 9 is over the 20. If so, it displays the yellow bubble. If neither of these conditions are present, then no bubbles.

I tried to create code using OR and if-then-else conditions, but I couldn't get it to work for the bubbles. Any help would be GREATLY appreciated!!

Thank you!!!
 
@KevinSammy Your best bet is to divide and conquer... By that I mean do all of your calculations prior to AddChartBubble() that is possible... Determine if each EMA crossover is true first... Then use the results within the AddChartBubble() call... Or you might be able to do more logic beforehand... I may not have time until later to look at this in-depth but that's the crux of things...
 
@KevinSammy Your best bet is to divide and conquer... By that I mean do all of your calculations prior to AddChartBubble() that is possible... Determine if each EMA crossover is true first... Then use the results within the AddChartBubble() call... Or you might be able to do more logic beforehand... I may not have time until later to look at this in-depth but that's the crux of things...

Thanks. I will try this.
 
I am trying to get chart bubbles to display on a one minute chart that uses a MTF of five minutes - i.e. use data from a five minute chart from behind the scenes and display it on a one minute chart.

Desired solution:
1) the bubble should display on the candle that meets the criteria (right now, it places on the candle on the first minute of the 5 minute candles)
2) able to put text next to the candle. I am using a round function so that prices are displayed to the default .0x place, but when I try to put something in quotes before the rounding function, it doesn't work.

Here is the code (I excluded the lines that would make this confusing - I'm not a great programmer like many of you lol)......if you guys can PLEASE HELP. Thank you!!

Code:
input agg = AggregationPeriod.five_MIN;
AddChartBubble(ema9 > ema20, roundup (close(period =agg)), high, Color.light_green, yes);
 
I am trying to get chart bubbles to display on a one minute chart that uses a MTF of five minutes - i.e. use data from a five minute chart from behind the scenes and display it on a one minute chart.

Desired solution:
1) the bubble should display on the candle that meets the criteria (right now, it places on the candle on the first minute of the 5 minute candles)
2) able to put text next to the candle. I am using a round function so that prices are displayed to the default .0x place, but when I try to put something in quotes before the rounding function, it doesn't work.


Here is the code (I excluded the lines that would make this confusing - I'm not a great programmer like many of you lol)......if you guys can PLEASE HELP. Thank you!!

input agg = AggregationPeriod.five_MIN;

AddChartBubble(ema9 > ema20, roundup (close(period =agg)), high, Color.light_green, yes);

See if this helps. The 'cond' will help limit the plotting of bubbles to one candle on the lower chart agg when triggered by the higher agg 'cond'.
Code:
input agg  = AggregationPeriod.FIVE_MIN;
plot ema9  = ExpAverage(close(period = agg), 9);
plot ema20 = ExpAverage(close(period = agg), 20);
def cond   = if ema9[1] < ema20[1] and ema9 > ema20 then BarNumber() else Double.NaN;
input bubblemover_updown = 3;#Moves bubbles up or down away from other candles
AddChartBubble(BarNumber() == cond,
               low - bubblemover_updown * TickSize(),
               "EMA 9>20 \n @" + (RoundUp (close(period = agg))),
               Color.LIGHT_GREEN, no);
Capture.jpg
 
I would like the bold code to show as a bubble on the MACD line.
(1, " STATUS : " + Round(MACD_Line, 5) + (if MUP then " RISING " + "" else if MDN then " FALLING " + "" else " NEUTRAL "),
if MUP then Color.GREEN else if MDN then Color.RED else Color.YELLOW);


THE COMPLETE CODE IS BELOW

Code:
input period = 7;
input hideCandles = no;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input movingAverageType = {default Exponential, TEMA};

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);
case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);
}

def haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
def haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
def haLow =  Min(lowMA, Min(haClose, haOpen));
def haHigh = Max(highMA, Max(haClose, haOpen));
def trend1 = haClose >= haOpen;
def trendup = trend1 and !trend1[1];
def trendd = haClose < haOpen;
def trendDown = trendd and !trendd[1];
def arrowup = trendup;
def arrowdown = trendDown;
def trigger = if arrowup then 100 else if arrowdown then -100 else trigger [1];

################################################################
input price = close;
input BBlength = 10;
input BBNum_Dev = 1.0;
input MACDfastLength = 12;
input MACDslowLength = 26;
input MACDLength = 5;

def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);

plot MACD_Line = MACD_Data;
MACD_Line.AssignValueColor(if MACD_Line > 0 then Color.GREEN else Color.RED);

def ML4A = 15.1 - 20;
def ML3A = 10.1 - 15;
def ML2A = 5.1 - 10.0;
def ML01A = 0.1 - 5.0;
plot zero = 0;
def ML1B = -0.1 - -5.0;
def ML2B = - 5.1 - -10.0;
def ML3B = -10.1 - -15;
def ML4B = -15.1 - -20;

zero.AssignValueColor(if MACD_Line < 0 then Color.RED else Color.GREEN);
zero.SetLineWeight(3);
################################################################
AddLabel (yes, if close then " ||| " else "", Color.BLUE);
AddLabel (yes, if close then " MACD " else "", Color.LIGHT_GRAY);
input n = 1;

def MUP = MACD_Data > MACD_Data[n];
def MDN = MACD_Data < MACD_Data[n];
AddLabel(1, " STATUS : " + Round(MACD_Line, 5) + (if MUP then "  RISING " + ""  else if MDN then "  FALLING " + "" else " NEUTRAL "),
if MUP then Color.GREEN else if MDN then Color.RED else Color.YELLOW);

################################################################
AddLabel (yes, if close then "|" else "", Color.BLUE);

AddLabel(yes, if MDN and MACD_Data <  ML4A then " " else "", Color.RED);
AddLabel(yes, if MDN and MACD_Data < zero then "0" else "", Color.WHITE);
AddLabel(yes, if MDN and MDN < ML1B then " " else "", Color.RED);
AddLabel(yes, if MDN and MDN < ML2B then " " else "", Color.RED);
AddLabel(yes, if MDN and MDN < ML3B then " " else "", Color.RED);
AddLabel(yes, if MDN and MDN < ML4B then " " else "", Color.RED);

################################################################
AddLabel(yes, if MUP and MUP > ML01A then " " else "", Color.GREEN);
AddLabel(yes, if  MUP and MUP > ML2A then " " else "", Color.GREEN);
AddLabel(yes, if  MUP and MUP > ML3A then " " else "", Color.GREEN);
AddLabel(yes, if  MUP and MUP > ML4A then " " else "", Color.GREEN);
AddLabel(yes, if  MUP and MUP > zero then " 0 " else "", Color.WHITE);
AddLabel(yes, if  MUP and MUP > ML1B then " " else "", Color.GREEN);
AddLabel(yes, if  MUP and MUP > ML2B then " " else "", Color.GREEN);
AddLabel(yes, if MUP and MUP > ML3B then " " else "", Color.GREEN);
AddLabel(yes, if  MUP and MUP > ML4B then " " else "", Color.GREEN);

def CrossUP = if MACD_Data crosses above zero
               then BarNumber() else Double.NaN;
def CrossDN = if MACD_Data crosses below zero
               then BarNumber() else Double.NaN;

AddChartBubble(BarNumber() == HighestAll(CrossUP), zero, " B ", Color.LIGHT_GREEN);
AddChartBubble(BarNumber() == HighestAll(CrossDN), zero, " S ", Color.LIGHT_RED);
 

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