Moving Average Crossovers For ThinkOrSwim

ill strike a deal with you... if you find the WORKING code for finding the 9ema crossing the 20ema and ill post the rest of your requested code. But you have to do the find, not someone else. you can either search on this forum and find it (maybe possibly even this thread ) or you can use the TOS built in scan wizard which is pretty straight forward, trust me its should be fairly easy to accomplish with a little bit of effort.
I got the EMA crossover figured out, I still haven't been able to find the 2nd part of my conditions Im looking for. I can figure out how to get to scan for if the closing price crosses above EMA 20, but can't figure out how to get it to scan for two green 1 min candles above EMA 20.
 
Last edited:
@Johnwhhansen
Here is price LOW is greater than or equal to 20 EMA ATLEAST twice in past 5 minutes
you have to set this on the 1 minute aggregation

Code:
def AboveEMA = low is greater than or equal to MovAvgExponential("length" = 20)."AvgExp";
def Count = Sum(AboveEMA, 5);
def Count2 = Count>=2;
plot scan = Count2;
 
Last edited:
What are the indicators used here?

ZL6EWzY.png
 
Happy Sunday Everyone,

Could anyone help on a script for daily 20EMA cross 50EMA cloud color on daily bar chart? If the 20ema cross above 50ema, the cloud area is green, otherwise the cloud area is red. I would like to incorporate the daily BTD indicator with the 20EMA and 50EMA cloud to identify whether or not stocks are still on trending.
Thank you for your help.
 
Happy Sunday Everyone,

Could anyone help on a script for daily 20EMA cross 50EMA cloud color on daily bar chart? If the 20ema cross above 50ema, the cloud area is green, otherwise the cloud area is red. I would like to incorporate the daily BTD indicator with the 20EMA and 50EMA cloud to identify whether or not stocks are still on trending.
Thank you for your help.
This is pretty straight forward.... You need to just add the study to the TOS chart (daily) and change the "inputs" (Price = close, Fast = 20, Slow = 50 and Average type = Exponential).... It's a VERY useful stript 'cause it's so customizable... 😁
 
Using the Ma Crossover as a starting point I'm trying to setup an indicator is show an up arrow on the chart when and where the 8sma crosses above the 21sma, and to show a down arrow when and where the 8sma crosses below the 21sma.

The Standard MA crossover in TOS will only allow you to choose one direction so you'd need to add it twice to your chart, and then set one to be "above" and the other to be "below". I'd like to be able to do both in the same script, but I keep running into issues. I even tried using the condition wizard which wasn't much help. It would create a sensible script, but then I get tripped up with the plotting portion and trying to assign colors.

I got this from the wizard, but getting it to plot correctly has been a pain.

def Signal = SimpleMovingAvg("length" = 8)."SMA" crosses SimpleMovingAvg("length" = 21)."SMA";
 
Modify for your own use....Scott

Code:
##### Begin Code #####

# SD_MA_Cross_Arrows
# Scott D
# Version: 02
# Original: October 26, 2020
# Last Mod: October 26, 2020

# Inputs
input price = close;
input EMA1 = 3;
input EMA2 = 9;

# Definitions
def MAshort = ExpAverage(close,EMA1);
def MAlong = ExpAverage(close,EMA2);
def UpSignal = MAshort crosses above MAlong;
def DwnSignal = MAshort crosses below MAlong;

# Arrows
plot bullish = UpSignal;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.GREEN);
bullish.SetLineWeight(3);

plot bearish = DwnSignal;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.RED);
bearish.SetLineWeight(3);

##### End Code #####
 
Last edited:
Hey Y'all, there is a very profitable trader Ripster.

https://www.tradingview.com/u/ripster47/#published-scripts

He trades his system here which is the 5/12 EMA cloud and the 34/50 EMA. I didnt find the cloud in TOS. I did those parameters and it looks very solid on his time 10 minutes time frame recommendation. Can anyone help with making a scanner to alert for when 5/12 CLoud crosses over the 34/50 for long and one for when the 5/12 cloud crosses below the 34/50 cloud? Belew is the simple cloud script for one of the EMA's. If anyone can help I would be very appreciative.

plot ema34 = ExpAverage(close, 34);
plot ema50 = ExpAverage(close, 50);
AddCloud(ema34, ema50, Color.ORANGE, Color.PLUM);
 
@PifogWallSt Clouds are for visual appearance only, based on conditional criteria, so we would never look for clouds themselves but, rather, the conditional criteria that causes them to react as they are coded to display... Now, that being said, all you need to do is to code your scan for the 5/12 and 34/50 criteria... Essentially, are 5 and 12 in a downtrend or uptrend when they cross above or below the 34 and 50... It might be as simple as monitoring for the 5 OR 12 crossing the 34 OR 50 because, if you examine the clouds you'll see consistent cloud colors in each direction without deviation... So perhaps you're overcomplication what should be simple EMA crossovers, which we have plenty of here in these forums... Take this information and run with it... You can use the scan wizard just as easily as anyone else can and the practice will be a good learning experience... We can help if you get stumped... There should be ample examples of similar scans here as well...
 
@PifogWallSt Clouds are for visual appearance only, based on conditional criteria, so we would never look for clouds themselves but, rather, the conditional criteria that causes them to react as they are coded to display... Now, that being said, all you need to do is to code your scan for the 5/12 and 34/50 criteria... Essentially, are 5 and 12 in a downtrend or uptrend when they cross above or below the 34 and 50... It might be as simple as monitoring for the 5 OR 12 crossing the 34 OR 50 because, if you examine the clouds you'll see consistent cloud colors in each direction without deviation... So perhaps you're overcomplication what should be simple EMA crossovers, which we have plenty of here in these forums... Take this information and run with it... You can use the scan wizard just as easily as anyone else can and the practice will be a good learning experience... We can help if you get stumped... There should be ample examples of similar scans here as well...
Let me have a honest crack at it and if I cant figure it out within a reasonable time I will reach out back out for help. Thank you
 
Let me have a honest crack at it and if I cant figure it out within a reasonable time I will reach out back out for help. Thank you
@PifogWallSt Clouds are for visual appearance only, based on conditional criteria, so we would never look for clouds themselves but, rather, the conditional criteria that causes them to react as they are coded to display... Now, that being said, all you need to do is to code your scan for the 5/12 and 34/50 criteria... Essentially, are 5 and 12 in a downtrend or uptrend when they cross above or below the 34 and 50... It might be as simple as monitoring for the 5 OR 12 crossing the 34 OR 50 because, if you examine the clouds you'll see consistent cloud colors in each direction without deviation... So perhaps you're overcomplication what should be simple EMA crossovers, which we have plenty of here in these forums... Take this information and run with it... You can use the scan wizard just as easily as anyone else can and the practice will be a good learning experience... We can help if you get stumped... There should be ample examples of similar scans here as well...
This is far as I could get but I dont know how to marry the two together. THinkScript comes up red at the word "and"

input price = close;
input length1 = 5;
input length2 = 12;
input averageType1 = AverageType.EXP;
input averageType2 = AverageType.EXP;
input crossingType = { below};

def avg1 = MovingAverage(averageType1, price, length1);
def avg2 = MovingAverage(averageType2, price, length2);

plot signal = crosses(avg1, avg2, crossingType == CrossingType.above);

signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == CrossingType.above then signal.color("Above") else signal.color("Below"));

signal.SetPaintingStrategy(if crossingType == CrossingType.above
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);

and

input price = close;
input length1 = 34;
input length2 = 50;
input averageType1 = AverageType.EXP;
input averageType2 = AverageType.EXP;
input crossingType = { below};

def avg1 = MovingAverage(averageType1, price, length1);
def avg2 = MovingAverage(averageType2, price, length2);

plot signal = crosses(avg1, avg2, crossingType == CrossingType.above);

signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == CrossingType.above then signal.color("Above") else signal.color("Below"));

signal.SetPaintingStrategy(if crossingType == CrossingType.above
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);
 
@PifogWallSt If you are creating scan code you don't need any formatting code at all because there isn't anything being displayed by the code other than the results... Scrap all that...

In addition, you need to do all defining first, then your processing, then your conditional criteria for results... So, essentially, you define all of your parameters... Then you get all of your average data... Then you use your conditional criteria to generate all of your plot signals... You're not writing a Study, unless that's what you want...

You should be able to do all of this using the Stock Hacker Scanners Condition Wizard rather than hand-coding... Or most of it... That will speed things up and insure accuracy... You're just making your job harder than it needs to be... I'll post an example but will leave it up to you to try to figure out the rest...

I will be using the Condition Wizard at first to get the initial logic done... I will use a Function named ExpAverage rather than a Study...

kLWXhOI.png


sfXuwWR.png


Which yields this in the Condition Wizard panel... One thing I should point out is that in the first line there is no length in the second ExpAverage reference because 12 is the default so the wizard omits it... I added in manually as seen further down...

zqZrLWO.png


Now I have the crux of my average data and barely used the keyboard, and no wasted code... EMA5 is above the EMA 12 and EMA34 is above EMA50... Next we'll edit our correct code and proceed...

Now we can see the following by clicking into the Thinkscript Editor panel from the Condition Wizard Panel... Notice that I manually add the length = 12 here as mentioned above... This is optional due to 12 being ExpAverage's default length...

QA8JQ5J.png


And here is the resulting code to plot, or select in the scanner, symbols whose fastCloud crosses above the slowCloud within a given number of bars of your choosing...

ssQqpQL.png


And, as you can see, we got 786 results by scanning All Symbols... I would then add more filters to refine my results, such as volume and price range...

RptDZEM.png


Once you have the additional filters added you can save this as your UpTrend scan... Then edit the code to say "crosses below" and save as your DownTrend scan...

And if you still want a Study you can use this known working code as your starting point and add proper display code complete with clouds, etc...

Isn't that easier than banging out code by hand and dealing with errors...??? It at the very least gets the lions share of the logic working... Let me know if this works for you... Work smarter, not harder... ;)
 
Last edited:

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