• LIMITED TIME OFFER: use coupon code PRIMEDAY (case sensitive) at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22. Biggest discount this year!

Add a Chart Bubble when 50SMA crosses below 100SMA

Branch

Member
VIP
I would like to have have a bubble show on my chart when the 50MA crosses below the 100MA; the bubble text will be state "Short". Can anyone help me with this?
 

BenTen

Administrative
Staff
VIP
Adjust the inputs to your liking.

Code:
# Moving Average Crossover With Arrows, Alerts, Crossing Count and Bubble at Cross
# Mobius
# Chat Room Request 01.25.2017

input price = close;
input fastLength = 20;
input slowLength = 50;
input averageType = AverageType.EXPONENTIAL;

plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));

plot ArrowUp = if FastMA crosses above SlowMA
               then low
               else double.nan;
     ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
     ArrowUP.SetLineWeight(3);
     ArrowUP.SetDefaultColor(Color.Green);
plot ArrowDN = if FastMA crosses below SlowMA
               then high
               else double.nan;
     ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
     ArrowDN.SetLineWeight(3);
     ArrowDN.SetDefaultColor(Color.Red);
Alert(ArrowUp, " ", Alert.Bar, Sound.Chimes);
Alert(ArrowDN, " ", Alert.Bar, Sound.Bell);
def countUP = if FastMA crosses above SlowMA
              then 1
              else if FastMA > SlowMA
                   then countUP[1] + 1
              else if ArrowDN
                   then 0
                   else countUP[1];
AddLabel(1, "Count UP = " + countUP, color.white);
def CrossBar = if FastMA crosses SlowMa
               then barNumber()
               else double.nan;
AddChartBubble(barNumber() == HighestAll(CrossBar), FastMA, "Cross", color.cyan);
# End Code
 

horserider

Well-known member
VIP
You said you wanted to be taught. So look where averagetype is used in the study. And change the averagtype for the plot you want to change. Looks like you wanted a 50 EMA cross of 75 SMA. So think how you would do that.
 

RoyalBlue

New member
don't need help with that part exactly, I mean, like for example I just want to alert, when SMA(A) cross EMA(B).
like a message alert, so how do i go about it?... like can you guide me a bit?

You said you wanted to be taught. So look where averagetype is used in the study. And change the averagtype for the plot you want to change. Looks like you wanted a 50 EMA cross of 75 SMA. So think how you would do that.
 

BenTen

Administrative
Staff
VIP
@Buckbull You can setup a scanner and save it as a watchlist.

u3WnEBz.png


Here is the thinkScript code for the scanner:

Code:
close crosses SimpleMovingAvg("length" = 20)."SMA"
 

Branch

Member
VIP
@Buckbull hang in there! This forum is the best forum I ever been apart of and I have been at this since TD Ameritrade brought/partnered with ThinkOrSwim. And I am just now learning the scripting (I have been wasting time doing other things in my life). BenTen provided you a great link.
 

Similar threads

Top