# 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
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?
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.
# 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
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;
@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...
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);
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);
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.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
O | Why does this AddChartBubble add a bubble to all the bars? | Questions | 2 | |
S | AddChartBubble on Chart Randomly BLACKS OUT ( cannot see text inside bubble ) | Questions | 8 | |
M | How to roundup in addchartbubble value | Questions | 1 | |
A | exit on AddChartBubble | Questions | 2 | |
S | help addchartbubble | Questions | 1 |
Start a new thread and receive assistance from our community.
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.
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.