This is a collection of handy thinkscripts for use on the thinkorswim (TOS) trading platform. There are two types of ThinkScript:
-
ThinkScripts
These scripts are full powered and intended for use on charts, scan queries, and conditional orders. The instructions for importing/exporting ThinkScripts applies to these scripts. -
Custom Quote Scripts
These scripts are intended for use on watchlists, anywhere a custom quote can be inserted as a column, and scan queries. To use these, the user must copy and paste the code into a custom quote thinkscript code area. TOS offers 20 custom quote slots.
The workflow for ThinkScripts and Custom Quote Scripts can be made much
more fluid once TOS enables features open to builtin scripts to user
created scripts. These are features such as the #Wizard
keyword, direct
referencing of user created scripts (not just builtin
scripts), not creating a copy of referenced thinkscript code when referencing
them as a condition in a custom script (this causes changes in the original
to not propagate to the custom script), etc.
PM Rank
Calculates the percentile rank for the current value of the selected
Fundamental Data (IV, Price, etc.) as it compares to its range over a
user or chart specified number of periods (FIVE_MIN, DAY, etc).
It is essentially (value-lowest)/(highest-lowest)
. This script can be
used as a plot and as a label.
PM Percent Change
Calculates the percent change in value from now and N periods ago where:
- value is any data type enumerated by Fundamental Data such as CLOSE, IV, etc.,
- N is any user specified lookback length, and
- period is any user or chart selected aggregation period such as FIVE_MIN, DAY, etc.
This script can be used as a plot and as a label.
PM Show OHLC
Plots the previous day's OHLC and today's OHL.
PM Sandbox
A playground to wrangle with thinkscript syntax, functions, and assumptions.
PM IV Rank CQ
A bare bones distilled version of PM_Rank that only computes the IV Rank
over 252 trading days rounded to one significant digit (one decimal place).
Note, this script colors the value based on where it lays within the rank.
Edit the code to change the lookback period and rank coloring thresholds
to fit your needs.
PM Price Rank CQ
A bare bones distilled version of PM_Rank that only computes the Price Rank
over 252 trading days rounded to one significant digit (one decimal place).
Note, this script colors the value based on where it lays within the rank.
Edit the code to change the lookback period and rank coloring thresholds
to fit your needs.
PM Rank CQ
A bare bones distilled version of PM_Rank with less user input controls. It
calculates the percentile rank over 252 trading days for desired fundamental
data (IV, O, H, L, C, Volume, etc.). Note, this script colors the value based
on where it lays within the rank. Edit the input data source or the lookback
period and rank coloring thresholds to fit your needs.
This one is intended to be imported as a study and referenced for custom quote scripts and scan queries. Once TOS fixes workflow issues, this will be the preferred method so there will be one source file for Rank related computations. Until then, it's easier/faster to use the rank specific cq scripts above.
PM Rank Coloring CQ
This is an example script to show how one can enable the coloring of data
if the core script is referenced. As of 2013-11-09, the TOS limitations
will essentially copy the core script code into a custom script using the
script { }
notation and add the coloring details below it.
PM Percent Chg CQ
A bare bones distilled version of PM_PercentChg that only computes the %chg
over 10 trading days rounded to one significant digit (one decimal place).
Note, this script colors the value based on hi and lo alert thresholds.
Edit the code to change the data type, lookback period, and alert coloring
thresholds to fit your needs. Also, this script minimizes column space by
not outputting the "%" character.
Enumerated below are a few ways to obtain these scripts:
- Clone this project in the following ways:
- Click on the
Clone in Desktop
link located on the right sidebar on GitHub - Run
git clone https://github.com/dranem05/thinkscripts-pub.git
locally
- Click on the
- Download an untracked version of these files:
- Click on the
Download ZIP
link located on the right sidebar on GitHub - Unzip the dowloaded archive to a local directory
- Click on the
- Download a specific script:
- Navigate to the file on GitHub
- Click on the source file
- Click on
Raw
to download the file
- Download this project into a local directory
- Fire up TOS
- Open up a chart
- Click on the
analysis tools
icon (looks like something dripping) - Click on
edit studies
- Click on
import
on the bottom of the left panel - Navigate to the thinkscripts directory where you dowloaded this project
It should be somewhere like:path/to/download/thinkscripts-pub.git/thinkscipts/
- Select the desired study and click open (or just double click the desired study)
The script should now be available in your TOS database.
- Get the latest version of the script
rungit pull origin
if you created a local clone of this project - Fire up TOS
- Open up a chart
- Click on the
analysis tools
icon (looks like something dripping) - Click on
edit studies
- Click on
import
on the bottom of the left panel - Navigate to the thinkscripts directory where you dowloaded this project
It should be somewhere like:path/to/download/thinkscripts-pub.git/thinkscipts/
- Select the desired study and click open (or just double click the desired study)
- You will be asked if you really want to replace the study in TOS
- Click on
Yes
Note, that the "latest version of the script" could be local edits you made in your local copy of the file outside of TOS. The same steps above allow you to update the TOS version of the script.
If you edit the thinkscripts via TOS, you can export these edits to your local copy of this project.
- Navigate to the script via the
edit studies
window - Click on
export
- You will be asked where you would like the study to be exported
- Export to your local directory of thinkscripts
- Confirm your desire to overwrite the local copy with this new copy
If your local thinkscripts directory is a git clone location, you can use it to maintain your own version controlled copy of the scripts.
- Navigate to the
Condition Wizard
tab- For Custom Quotes
- Follow the instructions in the "How Do I Install/Update
Custom Quote Scripts" section up to the step just prior
to clicking on the
thinksScript Editor
tab. - Click on the
Condition Wizard
tab.
- Follow the instructions in the "How Do I Install/Update
Custom Quote Scripts" section up to the step just prior
to clicking on the
- For Scan Query Criteria
- Click on the
Scan
tab - Click on
Add Study Filter
- Click on the study selector widget
- Click on the
Custom...
option
- Click on the
- For Custom Quotes
- Click on
Edit
orAdd Condition
- Click on the study selector widget
- Click on the
Study
option - Search for the desired study
- Update input parameters if applicable
- Select which plot to use as the scripts value
- Select your comparison operator, etc.
IMPORTANT:
Once referenced, TOS essentially creates an exact copy of the referenced script and uses this copy. Thus any changes made to the original DOES NOT PROPAGATE to the custom script. You have to re-reference the script to propagate any changes that were made to the original.
Downloading and getting the latest updates from this GitHub repository are the same as with the regular ThinkScripts. Installing/Updating into TOS is a bit different.
- Right click on a column name in a watchlist type of widget
(or nearly anything that looks like a table with columns) - Click on
Customize
- Under the
Available Items
left side panel, search forcustom
- Click on the scroll icon that appears to the left of any
custom
item - Click on the
thinkScript Editor
tab in the window that appears - Copy and paste the custom quote script into this window
- Rename the script from
Custom
to whatever you like - Click on
OK
- Get the latest version of the script
- Right click on a column name in a watchlist type of widget
(or nearly anything that looks like a table with columns) - Click on
Customize
- Under the
Available Items
left side panel, search for the desired script - Click on the scroll icon that appears to the left of that script
- Click on the
thinkScript Editor
tab in the window that appears - Copy and paste the updated code into the thinkScript Editor
- Click on
OK
Code is under the MIT license.