Moving Average Crossovers For ThinkOrSwim

Hey guys, not sure if anyone has links to scanners like QULLAMAGGIE has.

But if not and if someone can make one I would really appreciate it.

Looking for one that finds stocks that the 50 day is over the 200 day moving average.

Heres a link qullamaggie.com/my-3-timeless-setups-that-have-made-me-tens-of-millions/

Anyways would really appreciate it. Thanks in advance.
Ruby:
SimpleMovingAvg("length" = 50)."SMA" is greater than SimpleMovingAvg("length" = 200)."SMA"
Shared Scan Link: http://tos.mx/AtIaDTp Click here for --> Easiest way to load shared links
VRhxoWV.png
 
Last edited:
Hello everyone, love the site, have learned so much, thank you.
I am looking for some help.
simple trading plan I have but want to see it better on the chart so I can also go back and see what I missed and what I did right.
I trade long and short based on candle bouncing off the 13, 48 and 200 ema.
I am looking for the candle to change color every time it closes above and below the 13, 48 and 200 EMA, lets say the color blue.
all the rest of the time the candle holds its original color.
I have it now when the ema crosses but that is delayed so doesn't work great so im looking for when the candle closes after it crosses up or down those Emma's.
I trade on 2 minute time frame and really only day trade AMD.
 
Hello everyone, love the site, have learned so much, thank you.
I am looking for some help.
simple trading plan I have but want to see it better on the chart so I can also go back and see what I missed and what I did right.
I trade long and short based on candle bouncing off the 13, 48 and 200 ema.
I am looking for the candle to change color every time it closes above and below the 13, 48 and 200 EMA, lets say the color blue.
all the rest of the time the candle holds its original color.
I have it now when the ema crosses but that is delayed so doesn't work great so im looking for when the candle closes after it crosses up or down those Emma's.
I trade on 2 minute time frame and really only day trade AMD.
@merc2226 Something like this? It's not my code, I just had it in my studies from this site. I don't remember where I got it from. I hope you find it useful.


input price = close;#hint price: The price used to calculate the crossover. <b>(Default is CLOSE)</b>
input fastLength = 13;#hint fastLength: The number of bars used to calculate the fast moving average. <b>(Default is 3)</b>
input slowLength = 200;#hint slowLength: The number of bars used to calculate the slow moving average. <b>(Default is 8)</b>
input slowAvgType = {default Simple, Exponential, Weighted, Wilders, Hull};#hint slowAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Expontential)</b>
input fastAvgType = {default Simple, Exponential, Weighted, Wilders, Hull};#hint fastAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Exponential)</b>
Input DoArrows = no;#hint DoArrows:Yes shows arrows to define crosses
Input DoPlots = yes;#hint DoPlots: Yes shows MA plots to define crosses. Default is 'YES'
Input DoAlerts = No;#hint DoAlerts:No turns off alerts
Assert( fastLength < slowLength, "fastLength ["+fastLength+"] must be less than slowLength["+slowLength+"]");

def fastAvg;
switch (slowAvgType) {
case Simple:
fastAvg = Average(price, fastLength);
case Exponential:
fastAvg = ExpAverage(price, fastLength);
case Weighted:
fastAvg = wma(price, fastLength);
case Wilders:
fastAvg = WildersAverage(price, fastLength);
case Hull:
fastAvg = HullMovingAvg(price, fastLength);
}

def slowAvg;
switch (fastAvgType) {
case Simple:
slowAvg = Average(price, slowLength);
case Exponential:
slowAvg = ExpAverage(price, slowLength);
case Weighted:
slowAvg = wma(price, slowLength);
case Wilders:
slowAvg = WildersAverage(price, slowLength);
case Hull:
slowAvg = HullMovingAvg(price, slowLength);
}

plot signalXup = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.above) else Double.nan;
signalXup.SetDefaultColor(Color.pink);
signalXup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signalXup.SetLineWeight(3);

plot signalXdn = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.below) else Double.nan;
signalXdn.SetDefaultColor(Color.Green);
signalXdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signalXdn.SetLineWeight(3);


Plot fast_Avg = If DoPlots then Fastavg else double.nan;
fast_Avg.SetDefaultColor(Color.pink);
fast_Avg.SetPaintingStrategy(PaintingStrategy.line);
fast_Avg.SetLineWeight(2);
Plot Slo_Avg = If DoPlots then Slowavg else double.nan;
Slo_Avg.SetDefaultColor(Color.cyan);
Slo_Avg.SetPaintingStrategy(PaintingStrategy.line);
Slo_Avg.SetLineWeight(2);
AddCloud(fastAvg, slowAvg, color.BLUE, color.DARK_orange );
#AddLabel(1, "Fast MA(" + fastLength + ")",color.pink);
#AddLabel(1, "Slow MA(" + slowLength + ")",color.cyan);

#Trigger alerts
#alert(Fastavg, "CHECK IT OUT", Alert.Bar, Sound.Ding);

AssignPriceColor(if close > FastAVG then color.green else color.red);
 
Please help!

How can I use addchartbubble to show "high" only when EMA20 Crosses below EMA50 occurs like I did with setpaintingstrategy function:
is there a way to get rid of else double.nan in addchartbubble function below??

Thank you,
Kden.

input ema20Length = 20;
input ema50Length = 50;

def ema20 = ExpAverage (close, ema20Length);
def ema50 = ExpAverage (close, ema50Length);

plot ema13_Darrow = if ema20 crosses below ema130 then high else double.NaN;
ema13_Darrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#addchartbubble(1, high, "Crosses: " + (if ema20 crosses below ema130 then high else double.nan), Color.UPTICK, no);
 
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
Anyway to this into a strategy to go long when Fast EMA crosses above Slow EMA and go short when the Fast EMA crosses below the Slow EMA and input position size?
 
Anyway to this into a strategy to go long when Fast EMA crosses above Slow EMA and go short when the Fast EMA crosses below the Slow EMA and input position size?
  1. copy&paste your script into the Strategy tab (to the right of the study tab)
  2. paste the following to the bottom of your script:
Ruby:
input PositionSize = 500 ;
#long
AddOrder(OrderType.BUY_TO_OPEN, ArrowUp , tradesize = PositionSize );
AddOrder(OrderType.SELL_TO_CLOSE, ArrowDN , tradesize = PositionSize);
#short
AddOrder(OrderType.BUY_TO_CLOSE, ArrowDN , tradesize = PositionSize );
AddOrder(OrderType.SELL_TO_OPEN, ArrowUp , tradesize = PositionSize);
 
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








Is it possible to add a label showing the distance to the crosses with colors? red color below orange close to below and above and finally green color above...
 
Is it possible to add a label showing the distance to the crosses with colors? red color below orange close to below and above and finally green color above...
It is not clear what you are asking.
ThinkScript does math well.

Example syntax is:
  • define the math :
    Rich (BB code):
    def redcolor_below_orangeclose =  put your mathematical calculation here ;
  • put the math in your label.
    Rich (BB code):
    AddLabel(yes, redcolor_below_orangeclose, color.gray);
 
Hello traders/scripters,

I need a script for this following study for my ToS.

A scanner/screener whenever the SMA21 (white line) crosses over the Moving Averages of 180 (red line) & 200 (yellow line) whenever(?)... open/high/close, anytime.
Possibly for the duration of 15mins. Maybe with a condition of volumes traded above >500k including Pre-market & After-hours.

Couldn't attach an image to show as an example but I hope the text helps.... cheers!

Figured the image part here

 
There are no stocks currently where the 21sma crosses the 180avg and the 200avg at the same time on the 15min aggregation.
There are no stocks currently where the 21sma crosses the 180avg and then the 200avg within 3 bars on the 15min aggregation.

There were a couple results for these crosses on the daily chart.
Adjust the "within 3 bars" and the aggregation to your needs
Shared scan link: http://tos.mx/ivhuavA Click here for --> Easiest way to load shared links
b0s6nTs.png
 
Hello Family,

I'm sure there is a previous thread for EMA 20 and EMA 200 scanner, however, I have been unsuccessful in locating the thread. If anyone could post the thread or script, I would greatly appreciate it. Thanks in advance.
 
Hello Family,

I'm sure there is a previous thread for EMA 20 and EMA 200 scanner, however, I have been unsuccessful in locating the thread. If anyone could post the thread or script, I would greatly appreciate it. Thanks in advance.

it is rare for someone to find exactly what they want. but this site does have almost everything imaginable. you might have to make some minor changes.

searching for
scan ema cross
results in 3 pages of links.
https://usethinkscript.com/search/885717/?q=scan+ema+cross&o=date

this shows how to configure the scanner to look for a crossing.
Moving Average Crossovers For ThinkOrSwim
https://usethinkscript.com/threads/moving-average-crossovers-for-thinkorswim.229/page-8#post-88617
post155, 156

or go to page 1 and read through the posts to find a code.
 
Was just wondering if is there anyway possible this script can be modified so the Golden and Death arrows both can be plotted at the exact time and location where the crossover is happening which is on the actual moving averages instead of the closing candles?
Why do the Golden and Death arrows do not plot on crossovers when adjusting the periods to 50MA and 200MA. Thanks in advance.

OG script is in the below in addition to images for your reference.


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
 
Last edited by a moderator:
Was just wondering if is there anyway possible this script can be modified so the Golden and Death arrows both can be plotted at the exact time and location where the crossover is happening which is on the actual moving averages instead of the closing candles?
Why do the Golden and Death arrows do not plot on crossovers when adjusting the periods to 50MA and 200MA. Thanks in advance.

OG script is in the below in addition to images for your reference.


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

to change the price level an arrow plots at, to be on the average,
replace low with slowma.

change this,
plot ArrowUp = if FastMA crosses above SlowMA then low else double.nan;

to this,
plot ArrowUp = if FastMA crosses above SlowMA then slowma else double.nan;

do the same with the arrowdn formula.

----------

you don't see arrows, because they are drawn on top of candles, which are the same color. if you zoom in, you will see them.

try changing arrow color to cyan, then the arrows will be visible.
ArrowDN.SetDefaultColor(Color.cyan);

this is why i like to plot arrows with a vertical offset, like 0.995, to move them away from candles, to make them easier to see.

plot ArrowUp = if FastMA crosses above SlowMA then (low * 0.995) else double.nan;

------------

golden isn't a number and has no meaning. if you mean an average of length 50, just say 50.
 
And just a final touch to it. Could you also add an input to show for clouds yes or no options?
Thank you so much halcyonguy! I really appreciate it! You're awesome.

Any follow up to this request? I just need a switch that lets me turn the cloud function on and off.
 
Does anyone know of a script that can give an alert of moving average crossovers?
Here are 100 posts in this thread alone that reference moving average crossover alerts perhaps one of them will suit you:
https://usethinkscript.com/search/973785/?q=alert&t=post&c[thread]=229&o=date

Here is how to do your own searches:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-58238

https://usethinkscript.com/threads/search-the-forum.12626/
 
Can someone help to create a watchlist that will show when the 3 EMA crosses over the 8 EMA w/ green color as well as when the 8 EMA crosses over the 3 EMA for a 1 min TF and will show how many bars up to I guess 5 bars.
Similar to this:

R9LNUNf.jpg



Okay. I tried but I do not know how to code. This is what I got so far and ity may be wy off. Any help will be greatly appreciated.

Code:
input price = close;
input fastLength = 3;
input slowLength = 8;
input averageType = AverageType.EXPONENTIAL;
input averageType2 = AverageType.SIMPLE;

def FastMA = MovingAverage(averageType, price, fastLength);
def SlowMA = MovingAverage(averageType2, price, slowLength);

     FastMA.SetDefaultColor(Color.GREEN);
     SlowMA.SetDefaultColor(Color.RED);
#LABEL
if FastMA Crosses ABOVE SlowMA then set

# End Code

@samer800 You have helped me a few times in the past so I was wandering if you have the capability to create a watchlist script that will show green w/ number of bars when 3ema crosses 8ema and red when the 8ema crosses the 3ema. I have tried but cannot get it to work. @MerryDay moved my question here: https://usethinkscript.com/threads/moving-average-crossovers-for-thinkorswim.229/page-11#post-113510
 
Last edited by a moderator:
@samer800 You have helped me a few times in the past so I was wandering if you have the capability to create a watchlist script that will show green w/ number of bars when 3ema crosses 8ema and red when the 8ema crosses the 3ema. I have tried but cannot get it to work. @MerryDay moved my question here: https://usethinkscript.com/threads/moving-average-crossovers-for-thinkorswim.229/page-11#post-113510
try this and adjust t he way you want.

CSS:
def FastMA = ExpAverage(close, 3);
def SlowMA = ExpAverage(close, 8);

def Condition = FastMA>SlowMA;
def barssince = if Condition then barssince[1] + 1 else 0;

def bar = if barssince>0 then  barssince else Double.NaN;

plot scan = bar within 3 bars;

scan.SetDefaultColor(Color.BLACK);
AssignBackgroundColor(if bar >= 10 then color.CYAN else if bar  >= 3 then color.GREEN else if bar  > 0 then color.YELLOW else 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
325 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