Moving Average Crossovers For ThinkOrSwim

Yeah I was able to do all that. But it only had options for a push notification or an alert on my mobile device. Isn't there a way to get a column on the watchlist that indicates whether or not the crossover has taken place?
 
It seems that the Golden Cross (50 day crossing over the 200 day) will, in many cases create a technical surge in price only because of the cross. So I was wondering if there was a way to go about scripting or scanning for stocks that are about to cross but havent yet.
 
Anybody know how to make a custom alert, or maybe it would have to be a study, for a close below 9-EMA? I went to the MarketWatch tab as it says in ToS help, but that doesn't put anything on the chart.
 
Anybody know how to make a custom alert, or maybe it would have to be a study, for a close below 9-EMA? I went to the MarketWatch tab as it says in ToS help, but that doesn't put anything on the chart.

Not an expert at scripting but would this work for ya?

Code:
def alert = close is less than MovAvgExponential()."AvgExp";
Alert(alert, "Close above 9 EMA", Alert.BAR);

or if you are looking for an alert just when price crosses below 9 ema, this below code might be what you want:

Code:
def alert = close crosses below MovAvgExponential()."AvgExp";
Alert(alert, "Close above 9 EMA", Alert.BAR);
 
@Learnbot Is that for a close below 9-EMA? It says "close crosses below" is that the same as closing below it or is that just crossing below, but can go back above it? If the two codes do both a cross below and close below that would be pretty helpful as well.
 
@FreefallJM03 The code @Learnbot provided should work based on your request.

Here is the cleaned up version:

Code:
input price = close;
input length = 9;
input displace = 0;

def AvgExp = ExpAverage(price[-displace], length);
def alert = close crosses below AvgExp;
Alert(alert, "Close below 9 EMA", Alert.BAR);
 
Very novice trader here so I apologize if this is a TOS 101 Question - but I'm looking for a scan that has the 8 EMA close to crossing above the 50 SMA on the hourly chart that I use. Can someone please help me with this. Every time I've tried on my own, the scan has the 8 EMA has crossed above the 50 SMA days before. Looking for something "Almost There" - thank you so much for anyone that can help.
 
@JDTrader Did you change the timeframe of your scanner to the Hourly timeframe?

vrpIWGz.png
 
Hi, is there a thinkscript that can change the color of the candle when two moving average crosses.

For example, if 10EMA crosses 20EMA from above , the candle color is BLUE. Otherwise, the color will be RED.
 
@ljyeang Try this:

Code:
input price = close;
input fastLength = 10;
input slowLength = 20;
input averageType = AverageType.EXPONENTIAL;

plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
def bullish = FastMA crosses above SlowMA;
def bearish = FastMA crosses below SlowMA;

AssignPriceColor(if bullish then color.blue else color.red);

If that is not what you want, here's another variant. Replace the last line from the script above with:

Code:
AssignPriceColor(if FastMA > SlowMA then color.blue else color.red);
 
New to thinkscript and I am making my 1st indicator. I have the code to plot the SMA for both 20, 200, and 50. What I want are arrows that show the 20SMA crossing above 200sma and down arrows crossing below. Can anyone school a newbie?
 
@chaseimo
here goes what you requested, remember to thumbs up if you found this post useful


Code:
declare lower;

def above = SimpleMovingAvg("length" = 20)."SMA" crosses above SimpleMovingAvg("length" = 200)."SMA";
def below = SimpleMovingAvg("length" = 20)."SMA" crosses below SimpleMovingAvg("length" = 200)."SMA";
plot arrowaabove = if above then above else Double.NaN;
plot arrowbelow = if below then below else Double.NaN;
arrowaabove.SetDefaultColor(Color.GREEN);
arrowaabove.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrowbelow.SetDefaultColor(Color.RED);
arrowbelow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
@chaseimo,
The simple way to achieve this is using the built in MovingAvgCrossover study https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MovingAvgCrossover. You can use the settings to decide whether you want crosses above or below.

The longer and more interesting way to do it is this:
Code:
declare upper;
input fast = 20;
input slow = 200;
input price = CLOSE;
def null = double.NaN;
plot S = SimpleMovingAvg(price, slow);
plot F = SimpleMovingAvg(price, fast);

plot CX_UP = if F crosses above S then F else null;
CX_UP.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

plot CX_DN = if F crosses below S then F else null;
CX_DN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Code Explanation:
  1. After the declaration that we want this on the uppermost pane, we input our lengths and price. We define null as double.nan, because somewhere I learned that it's supposed to be less resource intensive to declare this as a variable than call the double.nan each time you need it.
  2. plots for S and F are simple moving averages. If you don't want to plot them, you could just as easily make them def lines instead
  3. CX_UP (crossover up) and CX_DN (crossover down) use the if then else construction to decide whether the two plots have crossed. You could go old school and forego the built in crosses above / crosses below with code like
    Code:
    if F > S and F[1] < S[1]
    in place of crosses above... but really why except as a learning exercise... which this is. :)
  4. we set some painting strategy so we get arrows.
Thinkscript is powerful, and fun. Welcome to the community! You've found a place here at usethinkscript that has lots of really good people and fun.

happy trading,
mashume
 
@mashume You brought up a good point for members to follow, and for me to get back into the habit of myself... Anytime you can preload a variable that will be used repeatedly throughout a script you are optimizing the code which causes it to execute faster and with less overhead, whether executed on your local device or on the TOS servers... Not to mention that if we all were to do our part in reducing the burden we put on the TOS servers, the less we would be complaining about the latency we so often see during the trading day... Sure, even sloppy code will work, but at what expense...??? Thanks again for bringing this up... (y)
 
This is just a simple indicator for moving average crossover but added scanner, cloud, and alerts for additional visual effect and enhancement.

For example, if 5/10 EMA crossover is your strategy, then this indicator plot an up arrow on the golden cross and down arrow on the death cross. You can also use the scanner to scan for stocks with EMA crossover and the built-in alerts to let you know as it happens.

1XlzIJA.png


thinkScript Code

Rich (BB code):
# Moving Average Crossover With Arrows, Alerts, Crossing Count and Bubble at Cross
# Mobius
# Chat Room Request 01.25.2017
# Modified a bit by BenTen

input price = close;
input fastLength = 8;
input slowLength = 21;
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);

AddCloud(FastMA, SlowMA, Color.GREEN, Color.RED);
# End Code

Shareable Link

https://tos.mx/2ZED6i
Hello Ben. I'm looking for similar scanner, but slightly different. I need 50MA(Blue) crosses 200MA(Red), and can this scanner work on premarket crossovers? Please see picture for reference. Thank you

gxmQZSH.png
 

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