Using Custom Studies In The ThinkOrSwim Scan Hacker

Seeker77

New member
I'm new to ThinkScript but have some programming background. My questions:

1. I'm not interested in writing code that would generate a chart. I'm only interested in a scanner that would generate a list of symbols that meet the criteria as defined in the code. Do I still need a plot statement at the end even though my interest is only in a scanner?

2. Why is my code for defining a variable (with a Def statement) invalid. All I'm trying to do is to define a range of values for which RSI is true:

def Rnghi = (35 < RSI[5] =< 60) ;

I've tried Between function with the same result (invalid code)

Appeciate ANY comments. Anything at all will be gratefully received. Thanks!
 
Last edited by a moderator:
Do's & Don'ts when using custom scripts in the scan hacker

First, the following ONLY applies to stocks. The ToS platform does not provide the ability to use custom studies in the Option Hacker.
https://usethinkscript.com/threads/options-scan-hacker-in-thinkorswim.5114/page-4#post-82892

Second: TDA throttles complex scripts as part of its resource management schema. Which is why many of these throw an error: code that contains multiple script functions or recursion calculations, and / or references to several ToS indicators, etc...


To write the perfect scan script.
only include the definitions absolutely necessary to create the calculations for your scan condition.

If the study has script{} functions that lets you make choices. For example multiple choices for what type of average to use in your calculation: Hull, Exponential, etc.. or any other of the many "choices" associated with the studies that have been ported over from Tradingview, delete them. Hard code the one choice that you want to use in your calculation.
Script{} functions are the death of the scan hacker.

Do not include any of the formatting statements that are part of chart studies.
Those that start with SET or have COLOR serve no purpose in a scan study.

Now you are ready.
You have your concise necessary def statements, and you have ONLY one PLOT statement.


The ONE PLOT is what the scan hacker is going to scan for.
Your scan can filter on many conditions but they have to be incorporated into one, single PLOT.



Your 2nd question
def Rnghi = (35 < RSI[5] =< 60) ;
has multiple syntax errors.

When referencing a ToS study, the syntax is:
<StudyName>(parameter1=value1,.., parameterN=valueN ).<PlotName>
https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/reference

Here is a method to find the settings/syntax for inside the parenthesizes:
https://usethinkscript.com/threads/reference-syntax-and-indicator-settings-in-thinkorswim.5022/

For your example, assuming you are using all the defaults for your RSI, the parenthesizes can be empty.
def xRSI = RSI() ;

There are multiple variations in syntax to code your condition:
def Rnghi =
reference RSI()."RSI" from 5 bars ago is greater than 35 and
reference RSI()."RSI" from 5 bars ago is less than or equal to 60 ;
or
def xRSI = RSI() ;
def Rnghi = Between(xRSI[5], 35, 60);
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Between
or
def xRSI = RSI() ;
def Rnghi = xRSI[5] > 35 and xRSI[5] <= 60 ;

@Seeker77
While there is a learning curve associated with ToS; the good news is the parameters that apply to the scan hacker; apply to all ToS widgets: Watchlists, Conditional Orders, etc.. Learn one, ya learn them all.
 
Last edited:
Do's & Don'ts when using custom scripts in the scan hacker

First, the following ONLY applies to stocks. The ToS platform does not provide the ability to use custom studies in the Option Hacker.
https://usethinkscript.com/threads/options-scan-hacker-in-thinkorswim.5114/page-4#post-82892

Second: TDA throttles complex scripts as part of its resource management schema. Which is why many of these throw an error: code that contains multiple script functions or recursion calculations, and / or references to several ToS indicators, etc...


To write the perfect scan script.
only include the definitions absolutely necessary to create the calculations for your scan condition.

If the study has script{} functions that lets you make choices. For example multiple choices for what type of average to use in your calculation: Hull, Exponential, etc.. or any other of the many "choices" associated with the studies that have been ported over from Tradingview, delete them. Hard code the one choice that you want to use in your calculation.
Script{} functions are the death of the scan hacker.

Do not include any of the formatting statements that are part of chart studies.
Those that start with SET or have COLOR serve no purpose in a scan study.

Now you are ready.
You have your concise necessary def statements, and you have ONLY one PLOT statement.


The ONE PLOT is what the scan hacker is going to scan for.
Your scan can filter on many conditions but they have to be incorporated into one, single PLOT.



Your 2nd question

has multiple syntax errors.

When referencing a ToS study, the syntax is:

https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/reference

Here is a method to find the settings/syntax for inside the parenthesizes:
https://usethinkscript.com/threads/reference-syntax-and-indicator-settings-in-thinkorswim.5022/

For your example, assuming you are using all the defaults for your RSI, the parenthesizes can be empty.


There are multiple variations in syntax to code your condition:

or

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Between
or


@Seeker77
While there is a learning curve associated with ToS; the good news is the parameters that apply to the scan hacker; apply to all ToS widgets: Watchlists, Conditional Orders, etc.. Learn one, ya learn them all.
Thanks so much!
 

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