Scanner of 20SMA above 50SMA and stay true 90 bars


Category:
0
0

Hi Pete. I have visited your forum and looked at the questions about the stock scanner. One of the question raised was the custom study of 20EMA crossing 50SMA and also the Scanning SMA conditions that stay true.

I am looking for a study filter (without the wizard) in TOS and plot me the list of stocks that has 20SMA above 50SMA for say, 90 bars. I would love to see 20SMA stay above 50bars within 90 bars and no single day within 90 bars that 20SMA fall below 50SMA.

Must appreciated if you can give me some hints. Thank you.

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on October 21, 2020 2:45 am
157 views
0
Private answer

The simplest way to solve this is to use the Condition Wizard. However the request specifically stated "without the wizard". So I will provide both.

Custom Code Solution:

For the custom code solution the key is to create a variable for the opposite condition. Then check the desired number of previous bars and make sure the unwanted condition has NOT been true for any of those previous bars.

input withinBars = 90;
input maLengthOne = 20;
input maTypeOne = AverageType.SIMPLE;
input maPriceOne = close;
input maLengthTwo = 50;
input maTypeTwo = AverageType.SIMPLE;
input maPriceTwo = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
def conditionToAvoid = maOne < maTwo;
plot scan = Highest(conditionToAvoid, withinBars) < 1;

In this case, the variable named "conditionToAvoid" is the 20 period SMA being below the 50 SMA. The final line of code creates the scan signal. The signal is true only if the "conditionToAvoid" has not been true at any point within the set number of bars.

Condition Wizard Solution:

We absolutely can build this scan without writing a single line of code. We can add a new condition group to the scan called "None of the following", add a new Study Filter to that group. Then build the condition using nothing more than your computer's mouse/trackpad. Screenshots below shows the basic steps as well as the end result.

The following video demonstrates how to use the Condition Wizard for custom scans:

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

And this video shows you everything you ever wanted to know about building custom scans on Thinkorswim:

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

 

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on October 21, 2020 8:30 am
0
Thanks Pete. Works like a charm. You are really helpful.
( at October 21, 2020 10:07 pm)