Add a Chart Bubble when 50SMA crosses below 100SMA

Branch

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

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
 
R

RoyalBlue

New member
Can you teach me how to alter the code, so that it gives a alert, when 50EMA cross 75MA?
 
horserider

horserider

Well-known member
VIP
input averageType2 = averageType.SIMPLE;

Then apply averageType2 to the plot of your choice
 
horserider

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.
 
R

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.
 
horserider

horserider

Well-known member
VIP
Please be clearer in what you want.
Alert(FastMA crosses SlowMa, "", Alert.BAR, Sound.Bell);
 
B

Buckbull

Member
@BenTen I looked but I might be missing it , Is there an alert that could let me know any stock that touches the 20 day MA ? Thanks
 
BenTen

BenTen

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



Here is the thinkScript code for the scanner:

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

Buckbull

Member
How did you guys learn how to write script ? Trial and error ? A class? Self taught ? I want to learn can you point me in a direction ? Thanks
 
Branch

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.
 
horserider

horserider

Well-known member
VIP
@Buckbull On the ToS screen at the top , hover over "Education" click "Learning Center"
 

Similar threads

Top