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.
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.
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.
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.
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.
Getting back into Screening again. It gets easier all the time. Here are some additional tips that could make this potential confusing mess very simple. I'm not going to be giving specific directions, but general concepts. Important points that make producing these scans go much quicker.
Tip 6- As you may know, there are just limited number of Custom Quotes to create custom scan columns. (looks like 19) You've used these before. You can name then anything you want and then using the Custom Wizard, grab any plot from any indicator, and list those in a named column of your choosing.
Tip 7- The Custom Wizard creates code something like this:
You may remember when you first stated creating these Custom Quotes, you got a warning message telling you that IF you change the code in the study you are referencing, it will have no effect on the Custom Quote code you just created. This is true. You probably thought the same thing I did. What a pain: IF I have to change my study code, then for my Custom Quote to be current, I have to come back and totally recreate the Custom Quote from scratch again. This is pretty much true, but there is a simple way around this.
Tip 8- Here's the why the Custom Quote code does not dynamically update, when you update your study. Custom Quote code includes a copy of the original study. So when you make a change to your study code, the copied version is not updated. The trick is knowing that this copied version of your study code is invisible AND knowing how to make it visible.
Tip 9- I have a decent size monitor by still, it takes a little squinting to see the difference between positive and negative values so I always like to make positive values green and negative values red. This is how I discovered this trick. Remember that little bit of sample code we just created.
As you're looking at that code, press the Thinkscript Editor button. You'll see your code there unchanged. But now, because you're in the editor, you can change the code like this.
I use the variable named, power, but you can use any word you want. Though it;'s important to always use the same word. You'll see why in a moment. Don't forget the semicolon at the end of the line. It won't work otherwise. Now go ahead and save this and exit all the way out of the Custom Quote editor. Then right click on the column title, and select Edit. Now when you go back in and click on the Thinkscript Editor button, you'll see that code from the study you referenced is all there. Scroll down tot he very bottom and you'll see the original code you changed:
Now add these two additional lines. These will paint the positive values green and the negative values red.
Tip 10- Now that you have the code from the original study and the Custom Quote column code all in one place, it is very simple to simply to click Edit on the column title and make a quick change to some value in your study. Or... add a line or two. Of course if you make major changes, you can just paste the whole thing in there again. Just make sure it is in between the curly brackets.
Tip 11- When I have a study that I know I'll be using as a scan, I always include at the very bottom these two lines of commented code:
This way, when the Custom Quote Wizard copies in all my code, it also includes the comments. Then I simply un-comment those two lines and and instantly my Custom Quote is working the with green and red backgrounds to highlight positive and negative numbers.
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.
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
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.
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
Getting back into Screening again. It gets easier all the time. Here are some additional tips that could make this potential confusing mess very simple. I'm not going to be giving specific directions, but general concepts. Important points that make producing these scans go much quicker.
Tip 6- As you may know, there are just limited number of Custom Quotes to create custom scan columns. (looks like 19) You've used these before. You can name then anything you want and then using the Custom Wizard, grab any plot from any indicator, and list those in a named column of your choosing.
Tip 7- The Custom Wizard creates code something like this:
Code:
Momentum()."Momentum" is greater than 5 within 4 bars
You may remember when you first stated creating these Custom Quotes, you got a warning message telling you that IF you change the code in the study you are referencing, it will have no effect on the Custom Quote code you just created. This is true. You probably thought the same thing I did. What a pain: IF I have to change my study code, then for my Custom Quote to be current, I have to come back and totally recreate the Custom Quote from scratch again. This is pretty much true, but there is a simple way around this.
Tip 8- Here's the why the Custom Quote code does not dynamically update, when you update your study. Custom Quote code includes a copy of the original study. So when you make a change to your study code, the copied version is not updated. The trick is knowing that this copied version of your study code is invisible AND knowing how to make it visible.
Tip 9- I have a decent size monitor by still, it takes a little squinting to see the difference between positive and negative values so I always like to make positive values green and negative values red. This is how I discovered this trick. Remember that little bit of sample code we just created.
Code:
Momentum()."Momentum" is greater than 5 within 4 bars
As you're looking at that code, press the Thinkscript Editor button. You'll see your code there unchanged. But now, because you're in the editor, you can change the code like this.
Code:
plot power = Momentum()."Momentum" is greater than 5 within 4 bars;
I use the variable named, power, but you can use any word you want. Though it;'s important to always use the same word. You'll see why in a moment. Don't forget the semicolon at the end of the line. It won't work otherwise. Now go ahead and save this and exit all the way out of the Custom Quote editor. Then right click on the column title, and select Edit. Now when you go back in and click on the Thinkscript Editor button, you'll see that code from the study you referenced is all there. Scroll down tot he very bottom and you'll see the original code you changed:
Code:
plot power = Momentum()."Momentum" is greater than 5 within 4 bars;
Now add these two additional lines. These will paint the positive values green and the negative values red.
Code:
plot power = Momentum()."Momentum" is greater than 5 within 4 bars;
power.setdefaultColor(color.black);
assignBackgroundColor(if power >0 then color.green else color.red);
Tip 10- Now that you have the code from the original study and the Custom Quote column code all in one place, it is very simple to simply to click Edit on the column title and make a quick change to some value in your study. Or... add a line or two. Of course if you make major changes, you can just paste the whole thing in there again. Just make sure it is in between the curly brackets.
Tip 11- When I have a study that I know I'll be using as a scan, I always include at the very bottom these two lines of commented code:
Code:
power.setdefaultColor(color.black);
assignBackgroundColor(if power >0 then color.green else color.red);
This way, when the Custom Quote Wizard copies in all my code, it also includes the comments. Then I simply un-comment those two lines and and instantly my Custom Quote is working the with green and red backgrounds to highlight positive and negative numbers.
Last edited by a moderator: