The Complete Beginner’s Guide to Using Custom Thinkscripts

This tutorial will show you how to add custom Thinkscripts to your Think Desktop software. These instructions will walk you through how to set up any of the custom scripts I have published on my Google Site.

First, you download the file that you want to install:

Save it somewhere on your computer that you can remember to get to later:

If the file has a “.ts” file extension, then you are ready to import it and can skip to the next step. If it’s a “.zip”, then you need to extract it first. If you are on Windows, use WinZip. On a Mac, the built-in archive utility can’t extract password-protected “.zip” files. But Stuffit Expander (free download from can. When you extract the files, enter the donor password if required, then extract the “.ts” file somewhere you can remember to go find it.

Next, open Think Desktop, go to a chart, click on “Studies” and choose “Edit Studies”:

This brings up the “Edit Studies and Strategies” window. In the left pane is a list of all studies and strategies that are available for you to add to a chart. In the top pane there are the studies and strategies that are applied to the current chart, and the lower panel shows the parameters and settings you can change:

If you are importing a study, click the “Studies” tab in the upper left. If a strategy, then click the “Strategies” tab. Then to add the script you downloaded, click the “Import” button in the lower left corner. Browse to your file, and then click “Open”:

The file will be imported into your collection of studies. Now at any time you can scroll to it in your list and double click it to add it to any chart:

To see or modify the source code for any of the scripts, click the little parchment scroll icon next to its name.

And that’s it! You’re working with your scripts.

55 Responses to “The Complete Beginner’s Guide to Using Custom Thinkscripts”

  1. The Complete Beginners Guide to Thinkscript « Read the Prospectus Says:

    […] […]

  2. The Complete Beginners Guide to Thinkscript » ThinkOrSwim | Says:

    […] […]

  3. Reuven Says:


    I am reading for a while your wrtting here and I wonder if you can help write a code for me,I am not a programmer I tried to write no lack up till now. Please let me know what are your rate or maybe you have a better Idea for me.

    for example : I am trying to plot some signals using “Woodie CCI” for entry and exit
    I can enclosed the code ,it is mainly cut and paste/

    Hope to here from you soon

    Thanks Reuven

  4. Prospectus Says:

    I’ll send you an email

  5. Mark Caliano Says:

    Looking for help in altering the zig zag indicator so it would show labels on swings such as number of bars and and length of move. Is this possible? If so I would be happy to donate.
    Thank you

  6. summit Says:

    hi i want the range bar indicator for mt4 .please contact me

  7. Michael F Says:

    Hi, I am looking for thinkscript programmers and also someone to help me develop strategies for TOS Prodigio. Do you know anyone available for hire?
    Thanks again for your time,

  8. Prospectus Says:

    That would be me. Email me: readtheprospectus at gmail. I’m booked for the next two weeks though.

  9. TechO Says:

    Hi, I want to download weekly and monthly open/high/low/close data directly into Excel. How can I program or use your DDE programming to accomplish this for 1, 2, 3, etc weeks/months ago?

  10. Greg Kostyk Says:

    I wonder if you can help write a code for me. I’m interested in placing an alert / order based on a trendline break (oto with a trailing stop which of course is oco). The trailing stop would be a SMA + either a ATR volatility or Lookup as a confirming stop for exits. Please let me know what your rate is.

    Thanks for your site,


  11. sebby Says:

    im new at this, im looking for a way to scan for stocks by using CCI .
    can u help?

  12. Prospectus Says:

    Using CCI how?

  13. Jack Tooke Says:


    I have seen this request from people, but I have never seen the answer. I am trying to create a column on my watchlist that shows the current days volume as a percentage compared to the same time for the last 50 days. If the current days volume is higher than the average for the same time in days prior, then it would indicate the percentage above. If the percentage is below, then it would indicate the percentage below as a negative.

    I was able to write a thinkscript that compares the current days volume to a 50 day average. It works well, but the numbers don’t have any reference to compare until the day is over.

    Let me know how much you charge. I am new to thinkscript and would really appreciate any help.



  14. Phill Says:

    Hi, I was wondering anyone has or could build a trendline alert for TOS? I would want it to give an audiable alert anytime the trned line is broken, I would like to use it across all time frames if possible, Thx

  15. Domenic curko Says:

    Hi, I’m wanting to develop a simple RSI formula that can email me alerts when they happen. I reside in south africa I trade futures using the ( global trader ) platform. I use netdania charts

    Can you help



  16. Elie Says:


    I was searching for more info about thinkscripting and found your blog. I applause what you are doing, thanks.

    Just a quick question from my side because I haven’t found my answer yet. I’m looking to creating a custom watchlist column that displays the percentage change from the day’s open. Basically something like plot percentChange = (close/open -1 ) * 100.

    1- That doesn’t seem like the right open price and last price.
    2- It doesn’t seem to update in real time whenever the last price changes.

    Any pointers would be greatly appreciated. Thanks.

  17. Prospectus Says:

    Use (last-open)/open*100. Close is the day’s close, last is the last price.

  18. Permatrader (@permatrader) Says:

    Just an update about the percent change from open. The “last ” variable doesn’t exist. What I did is the following, as a watchlist custom column:

    def O = open(period=”DAY”);
    plot percentChange = round((close/O – 1)*100, 2);
    percentChange.DefineColor(“Positive”, Color.UPTICK);
    percentChange.DefineColor(“Negative”, Color.DOWNTICK);
    percentChange.AssignValueColor(if percentChange >= 0 then percentChange.color(“Positive”) else percentChange.color(“Negative”));

    The same code can be used for a custom study.
    Unfortunately, the updates in the watchlist are a bit laggy compared to the study itself but it works quite well.


  19. Deborah Fine Says:

    I have just downloaded the # Prospectus study named
    # CumTickv2STUDY

    I was wondering if there is somewhere I can go to get an explanation for using this study?

    If not, will you explain it?

  20. Prospectus Says:

    See here:

  21. tradable Says:

    hi! i like your work with TOS’s thinkscript. Would you happen to know the script for getting the bar number or exact time corresponding to the highest high/low on a 1 min Today chart? i’m trying to make a simple indicator that would in real-time show the time of day’s high/low or at least showing the number of bars that had elapsed from the day’s high/low to the current bar number. thank you.

  22. Tyler Ohlmann Says:

    Hi, I am not a programmer and would get some huge benefit from a particular function that I *think* thinkScript can execute. I was wondering if you’d be interested in helping me. I want something pretty simple – a watchlist of 100 or so stocks to give a notice when they are “inside” (low is greater than or equal to previous low and high is less than or equal to previous high) on a 30 min aggregation period. That’s it. I would like to be able to view if the condition is true DURING the period, with another column showing the prior periods TRUE’s. I would be happy to explain further (or clarify anything that wasn’t very clear!) if you think you could provide me some help. Thanks in advance.

  23. alex Says:

    Hi I like to implement your tick study, but TOS gives me this info.

    “Invalid statement: def at 12:1
    No such variable: range at 13:15
    calcValue: missing parameter”

    Any ideas on how to fix it? Thanks!

    p.s. don’t give up on your trading. trade the market not single stocks. don’t fight the market and create a plan. congrats on the child. best investment of all. best wishes.

  24. fernando Says:

    I’m running TOS DDE TEMPLATE and it does not handle options tickers.

  25. Prospectus Says:

    I’ll look into it

  26. Fred Says:

    Hi, I just came across your website-do you have code that will automatically make a trade for you based on specific stocks passing technical indicators and fundamental indicators that can be specified? If so, which file is a sample of this kind of code?

  27. Prospectus Says:

    No, I’m afraid I don’t.

  28. Agni Says:

    You are doing a great job in scripting. Appreciate that you are sharing your knowledge. I have a quick question on TOS scripting.
    Here is the part of my code.

    def signal = If(IsNaN(HBar), 0,
    If(spike = HBar, 1, 0)));

    Plot myhigh = if (signal == 1, high, 0);
    Plot mylow = if (signal == 1, low, 0);

    I am trying to get the High and Low of the signal bar. Unfortunately, due to tos scripting, it is overwriting the values. Is there anyway, we can just get the high and low of the signal bar without overwriting when we pass through the following non-signal bars.
    Thanks in advance.

  29. Prospectus Says:

    Yes, you use rec statements like this:

    Rec myhigh= if signal==1 then high else myhigh[1]; Rec mylow= if signal==1 then low else mylow[1];

    On Nov 12, 2012, at 2:27 PM, Read the Prospectus

  30. Chris Says:

    Any help? I have the below working. Not I want to be able to alert (I got the alert part although it is not here) when the price or close price of the last bar or agg period is within alertprice. Any help?

    input aggregationPeriod = AggregationPeriod.DAY;
    input length = 1;
    input displace = -1;
    input showOnlyLastPeriod = no;
    input alertprice = .05;

    plot PrevDayClose;
    if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PrevDayClose = Double.NaN;
    } else {
    PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);


  31. Prospectus Says:

    I’m not sure what you’re asking for?

  32. David Says:

    Perhaps you might be able to help with this. I’ve been trying to write ‘some’ code, some being the operative word there but i’m not having any luck. This is what i was trying to accomplish for a scan of the market… FLOAT<30000000 and RSI20 Again, this is just a simple scan for the market. Any help on this matter would be appreciated.

  33. David Says:

    Sorry for the 2nd post but apparently that RSI didn’t come out correctly. RSI is less than 50 and RSI is greater than 20.

  34. Prospectus Says:

    I’ll look at it

  35. pat doran Says:

    could you send an e-mail please hard to explain what i need

  36. pat doran Says:

    in addition what i have is proprietary

  37. Larry Says:

    Looking for 1 and 2 standard Deviation lines or labels based on current price..

  38. Bob Shirley Says:

    Can you do the Mansfield Relative Strength that Stan Weinstein referred to in his book? A link to a free online charting service that uses it is:
    What are your rates?

  39. Richard Says:

    Hi there

    Can you help with custom coding for an indicator on TOS?

    If so please email me and I will provide the details of what I want.


  40. toslancer Says:

    Hi there
    if you need help with thinkscript please email me: toslancer [at]

  41. ramzamma Says:

    hello sir, i have seen all your pages. let me introduce myself i am from india doing trades in nse exchanges and mcx exchangs following mt4 charts. but here you have given screen shots in some other method.. i am not have much knowledge to do all this download apply method and all… if you guide me i will do all things.. your methods are really superb sir. i want to get some profits out of trades sir because every time i am failing. guide me please .. to put any indicator for good successful trades
    thanking you

  42. Al Cohen Says:

    I track three factors of Keltner Channels (1,2, & 3) and want to scan for stocks whose candelsticks are more than 3 Keltner Channels out of norm. This is kind of a “reversion-to-mean” strategy. Do you have such a script or help me make one?

  43. Tony Says:

    I have a simple question, using “input” in declaring a max and min value for use in cystom stockhacker studies for scans doesn’t seem to work. Am I doing something wrong, is it supposed to work? Also I can’t seem to name my custom studies in the scanning tool. They are all defaulted to customs
    Thanks for any info

  44. Prospectus Says:

    Email me your code and I’ll look: readtheprospectus at gmail

  45. Fabio Says:

    could you email me? i would like to send you some code to look at. need your help.

  46. Slava Says:

    What your e -mail address where to throw confirmation of donation?

  47. john Says:

    I need an indicator programmed in think script. The indicator is currently coded for Metatrader 4.

  48. Abeda Sulemanji Says:

    Thank you for the scipts.Can you help identify a script with and EMA crossover of say 8 and with increasing volume ?

  49. Tiger Says:

    Hi, i’m part of a signals group and wanted to code some custom indicators for myself and learn tos scripts. Here is a link with videos to give you an idea of what i’m looking for:

    Do you have any sample code to get me started with, especially the pink/yellow/red arrow indicators. Thank you

  50. Prospectus Says:

    Email me readtheprospectus at gmail


  51. PSK Says:

    Can we the contents of the Guide? I will be happy to donate. Thanks

  52. PSK Says:

    Can we see the contents of the Think Script Beginner’s guide?

  53. Prospectus Says:

    This post is it! I didn’t mean it was a complete guide, it was a quick start for complete beginners. It wasn’t worded well.

    I should put together an actual guide though.


  54. C G Says:

    Have you updated MACrossover_w_AlertsSTUDY.ts I’ve tried unsuccessfully to create a moving avg crossover scan using a three hour period but think or swim will not allow me to use that period in scan because it is not default period. I could use the four hr. period but I don’t know thinkscript well enough to write my own. I have used different inputs that seem to give good signals using the 5/9 EMA or other similar timeframes which show great promise, but I cannot generate a result that identifies the exact day/time that it occurs and is many days later. I’d be more than happy to donate/follow if you have this scan. Please contract me at Thanks in advance for your time and consideration,

  55. Peter Ridge Says:

    for thinkorswim:

    Does anyone know how to plot current book value per share of a particular stock on a chart? These is a defined function BookValuePerShare but i can’t figure out how to plot it.

    For example the book value for JPM is currently $70, how do i plot a horizontal line at price point 70 on the chart? Thank you.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: