Stock Screener (Q&A, Tips & Tricks)

Townsend

Townsend

Member
VIP
Tip 1- You may find your Scan results aren't accurate at all. In that a chart of the same time frame does not match the parameters specified in your Scan. Probably the most important thing I learned is that the Scanner's Condition Wizard does not always use all the Input Parameters. So I never use it. Rather, I always used the other tab, the ThinkScrip Editor. You will be surprised to find how much can be done in straight away code. Even if you don't do much coding you should at least learn the basic format for providing all the required input parameters for your Scan. It's simple. Here's an example, you can use as a model.
Code:
def look = doubleMovingAverage("Fast" = 8, "Slow" = 22, "smooth" = 6).momentum;
plot see = if look <= 3 and look >= -3 then yes else no;
Let's analyze this little bit of code. 1- "doubleMovingAverage" is the exact name of your indicator. 2- "Fast" and "Slow" and "Smooth" are the exact names of Input values. Notice how these input values are strung together in between the parenthesis. 3- Very important: the ".momentum" after the parenthesis is the exact name of the Plot in the indicator you want to search on. Since the first line starts with "def look =" the value of the "momentum" plot is being placed into the look variable. 4- Next line we create a new Plot that that qualifies the Search parameters. In this example I'm searching for low momentum numbers, between -3 and 3. It's a pretty simple format. I think you'll find your charts match your search criteria much better using this method.

Also, once you enter code into the ThinkScript Editor box this way, TOS will copy the entire block of code from your indicator as a prefix to these few lines. That's fine. Just don't be surprised if you right click to Edit and see more code than expected. Just go down to the bottom and adjust your parameters as need be.
 
markos

markos

Well-known member
VIP
@Townsend have you ever written a Scan & Watchlist Column for the TOS built in LBR 3/10 Oscillator? If you have, thanks in advance. It would be good for this tutorial to show how to change that scan into a WLC with color for crosses in last hour, for example.

From @MBF post in Questions: I am looking for the 3/10MA to cross above the slow 16MA.

Code:
# TD Ameritrade IP Company, Inc. (c) 2011-2019
#Feel free to take out the switch & alternate-markos

declare lower;
input price = close;
input calculationMode = {default Normal, Alternate};

plot FastLine;
switch (calculationMode) {
case Normal:
    FastLine = Average(price, 3) - Average(price, 10);
case Alternate:
    FastLine = Average(price - Average(price[3], 3), 2);
}
plot SlowLine = Average(FastLine, 16);
plot Hist = FastLine;
plot ZeroLine = 0;

FastLine.SetDefaultColor(GetColor(1));
SlowLine.SetDefaultColor(GetColor(8));
Hist.DefineColor("Positive", Color.UPTICK);
Hist.DefineColor("Negative", Color.DOWNTICK);
Hist.AssignValueColor(if Hist >= 0 then Hist.color("Positive") else Hist.color("Negative"));
Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist.HideTitle();
ZeroLine.SetDefaultColor(GetColor(7));
 
  • Love
Reactions: MBF
Townsend

Townsend

Member
VIP
Question: Have you ever written a Scan & Watchlist Column for the TOS built in LBR 3/10 Oscillator?
Answer: Sorry. No. I don't even know what a LBR 2/10 Oscillator is. Or for that matter what WLC is.
@markos Maybe post this in a separate thread, with a screenshot of this Indicator. I'll have a look there.

Tip 2- I think the most powerful thing about TOS is that you can take any indicator or write a custom indicator and make it into a scan. In in Tip 1, I showed you how to make sure all your Input parameters get used in your Scan. It's an important lesson, knowing that you can use def and plot in the ThinkScript Editor. Which allows you to set up much more complex Scans than using the Condition Wizard.

But... for most cases you can use this simpler format to achieve the same results. Notice, all in one line and no semicolon.
Code:
doubleMovingAverage("Fast" = 8, "Slow" = 22, "smooth" = 6).momentum between 3 and -3
 
Last edited:
Townsend

Townsend

Member
VIP
Have you noticed that MANY scans end up timing out with no results. Sometimes they work and sometimes they don't. My best guess is that the code from your indicator is sent over to the TOS server and there, it runs the scan on some massive cloud based server. Of course with many thousands of TOS users, it's very busy so there is some kind of internal qualification code, that happens to determine whether or not there is time to return results you're asking for. This is wholly based on the complexity of you request. The number of Filter Lines on your San Query AND the complexity of your code. The result is very complex Scan requests always time out, with no results. Except maybe after hours and on weekend, when the server is not being used as much.

Tip 3- There is a way around this. What you need to do is break your Scan logic into two parts. The fist part is the readily available results for the Filter Lines. Easy Filters that you know always come back with results. THEN you put the complex code that the TOS server always rejects as a Column on your Scan Results WatchList. In this way the complex code in your indicator is never run on the TOS server. But because it is defined as a Custom Quote Column, your local computer (CPU) runs the code effortlessly. Sure. Rather that receiving a short little list from the TOS server, you end up with a massive list that contains MANY items that don't fit your criteria. But then, with a quick sort on your Indicator's Custom Quote , (clicking on the column heading), the results you're looking for, all jump to the top of the list. That's what I do.
 
Townsend

Townsend

Member
VIP
Tip 4- If you've done any coding, you've probably come across this message, "At least one plot should be defined." That's pretty simple. Any code, whether it be for an Indicator, Strategy, or Custom Column on a Watchlist, needs to have at least one way to display the data. But... that error message isn't quite right. You can add a Label using the addLabel() function, and that works just as well as a Plot.

Tip 5- Use Custom Quotes Columns on the Scan results, (just like on a Watchlist), to check and make sure your Scan is bringing back the correct results. This example code below, will display ALL results. Those that are True for myvalue > myvalue[1] and those that aren't. Ideally, if you Scan is working, you shouldn't see an No values.

Code:
addLabel (yes,
if myvalue > myvalue[1] then "Yes" else "No",   # displays true or not value as text
if myvalue > myvalue[1] then color.green else color.red);  #controls the color of the text
 
raghavag2004

raghavag2004

New member
2019 Donor
VIP
@Townsend

is it possible to share it as link ? just to import
 

Top