Scan for 20 EMA crossing 50 SMA


Category:
0
0

Hello Peter,

Can you convert this study for me to a scan?

input SMAPeriod1 = 20;
input SMAPeriod = 50;
input price = close;
def na = double.nan;

plot fastema = ExpAverage(price, SMAPeriod1);
plot slowema = Average(price, SMAPeriod);
def crossover = if fastema > slowema AND fastema[1] <= slowema[1] then 1 else 0;
def crossunder = if fastema < slowema AND fastema[1] >= slowema[1] then 1 else 0;

#Plot arrows
Plot up = if crossover then low – tickSize() else na;
Plot down = if crossunder then high + tickSize() else na;
up.SetPaintingStrategy(paintingStrategy.ARROW_UP);
down.SetPaintingStrategy(paintingStrategy.ARROW_DOWN);

#Trigger alerts
alert(crossover[1], “Crossover”, Alert.Bar, Sound.Ding);
alert(crossunder[1], “Crossunder”, Alert.Bar, Sound.Ding);

Marked as spam
Posted by (Questions: 5, Answers: 2)
Asked on September 4, 2020 6:27 am
181 views
0
Private answer

Corrected the question title from "Convert study to a scan" to "Scan for 20 EMA crossing 50 SMA". The title of the question should always describe the context of your request. "converting a study to a scan" could describe the vast majority of posts in the forum and is therefore far to vague to be useful.

Moved this question out of the "Frequently Asked Questions" topic and into the "Stock Scanners" topic. The questions should be posted in the topic that aligns with the requested solution.

There is no need whatsoever to convert your code to a scan. This scan already exists as a built-in scan that comes with Thinkorswim. The name of the scan filter is "MovingAvgCrossover". Screenshot below shows this scan filter applied to a scan and setup to match the code you provided.

Based on your request, I highly recommend you take the time to learn how to use the scan tools available on Thinkorswim. There is whole lot more available then you realize. Converting a study to a scan or writing custom code is rarely needed, once you learn how to use the tools.

The following videos will get you up to speed.

https://www.hahn-tech.com/thinkorswim-scans-beginner-to-advanced/

https://www.hahn-tech.com/thinkorswim-condition-wizard/

 

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on September 4, 2020 8:07 am