Tutorial: Formatting Plots Using Thinkscript for Think or Swim

I have had many requests in the past to change the default formatting of an indicator–color, line style, etc. This is easy to do, but not well documented. So here’s a tutorial on how to format plots in Think or Swim!

All indicators need to have at least one “plot” for them to show up on a chart. Let’s work with this example of a 20-period Exponential Moving Average:

plot myindicator=ExpAverage(close,20);

Once you have defined the plot, you can change many different parameters in this way:


You begin with the name of the plot. “FUNCTION” is a certain function you want to use, and “arguments” are any inputs to the function. Here’s some things you can do with your Thinkscript plots:

Set the Color

To set the plot’s default color, you can use the “SetDefaultColor()” function. To set the indicator to the color white, use this:


“Color.White” is an argument that tells Thinkscript to use the color white. Very complicated, I know. πŸ˜‰ Here’s a list of the different colors that are pre-defined in Thinkscript:


(FYI, the list is found under “Color” in the “Constants” section of the Thinkscript editor sidebar.) “Color.Uptick” and “Color.Downtick” match whatever you have set for these colors in the main chart settings panel.

Change the Color According to a Value

To change the color on the fly, you use the “AssignValueColor()” function. If you want to apply conditional color formatting, you can also use an if/then/else statement, like this:

myindicator.AssignValueColor(if close>=myindicator then Color.Green else Color.Red);

In our example, this code will recolor the EMA green if the close of a bar is above the EMA, and red if the close is below the EMA.

Set the Curve Style

You can change the line style of your indicator using the “SetStyle()” function. The possible arguments are:

curve.FIRM # The standard line
curve.INEDITABLE # Standard line, but cannot be changed by user
curve.LONG_DASH # Long dashes
curve.SHORT_DASH # Short dashes
curve.POINTS # Just a dot

So if you wanted your EMA to be long dashed, use this:


Set the Plot To a Histogram or a Line With Markers

The “SetStyle” command just applies to the standard curve. To use other styles, use the “SetPaintingStrategy() function. The possible arguments are:

paintingstrategy.HISTOGRAM # Plots with a bar from 0 to the value
paintingstrategy.LINE_VS_POINTS # Plots a line, but with dots at each value
paintingstrategy.LINE_VS_SQUARES # Plots a line, but with squares at each value
paintingstrategy.LINE_VS_TRIANGLES # Plots a line, but with triangles at each value

To make our EMA have a square at each point, use this code:


Set the Line Weight

To change the thickness of the plotted line, dot, marker or bar, use the “SetLineWeight()” function. The arguments are 1, 2, 3, 4, or 5. That’s it. The thinnest is 1 and the thickest is 5. This example sets the line to the thickest weight possible:


Dynamically Hide and Show the Plot

You can hide or show your plot programmatically with the function “SetHiding()”. The argument should be 0 for show, 1 for hide. If you wanted to show our EMA only when price was above today’s open, you could use this code:

myindicator.setHiding(if close>open(period="DAY") then 0 else 1);

Note that this will either hide or show THE ENTIRE plot based on the results of the “if” test in real time. This is what I do in my Formatted Pivot Points indicator to do dynamic hiding.

Now you know the basics of formatting your plots with Thinkscript! Leave a comment if you have any questions. For your convenience, here’s all the example plot code repeated below:

plot myindicator=ExpAverage(close,20);
myindicator.AssignValueColor(if close>=myindicator then Color.Green else Color.Red);
myindicator.setHiding(if close>open(period="DAY") then 0 else 1);

Tags: , ,

15 Responses to “Tutorial: Formatting Plots Using Thinkscript for Think or Swim”

  1. RappidFyre Says:

    Hey Pro,

    Your tutorial and breakdown is much appreciated as is your time and the time it took you to draft it up.

    πŸ’‘ You can actually create a tutorial series on the functions, workings and nuances of good ‘ol thinkScript. I’d definitely tune in for for the series.

    Keep up the great work


  2. stephne Says:

    Good post. Is there anyway to change the color of the price bar (Chart Bar) other than the two colors choice? I want the price bar to change color is for example Price Bar goes yellow if close is above 20 day ma. Price bar turns blue if close is below 20 day ma. Any suggestion?


  3. Prospectus Says:

    Yes, try this post:


  4. Feather Color Down Comforter Sets Says:

    Such a great post inspired people who read it..I’m waiting more good quality post from this, so bookmark!

  5. Geodepe Says:

    How would I set the background conditionally. For example,
    if MA1>MA3

    I get an error message saying I can not do this in branch statements. Any ideas appreciated.


  6. Prospectus Says:

    You have to do it inside of the assignbackgroundcolor statement, like this:

    assignbackgroundcolor(if MA1>=MA3 then color.cyan else color.pink);

  7. Geodepe Says:

    Thanks I thought I tried that, but it was showing arror..
    Now, it works … appreciate it.

  8. Alan Says:

    I tried to change the background color as follows:

    assignbackgroundcolor(if close > Average(close, 15) then color.green else color.red);

    I put the line in a custom study. However, the study does not work as I expect – it turns the whole background into one color instead of strips of green and red colors.

    I have searched through the interent and read another thread, but I still cannot solve the issue. (http://finance.dir.groups.yahoo.com/neo/groups/TOS_thinkscript/conversations/topics/9327)

    Please help. Thanks a lot!

  9. chall3809 Says:

    In your SetHiding() example you mention that the ENTIRE PLOT is hidden/shown.

    I’m having a hard time hiding/showing my indicator in a lower pane when there is an expansion area in the upper pane. However, I don’t want the entire plot hidden, just for the bars in the expansion area.

    How do I deal with this?


  10. Tiger Says:

    Appreciate your tutorial, very helpful. How can I have the dotted line showing red green dashes?

  11. parfum untuk miss v Says:

    Fantastic website you have here but I was curious if you knew of any discussion boards
    that cover the same topics discussed here? I’d really like to be a part of group where I can get
    suggestions from other knowledgeable people that share the same interest.
    If you have any suggestions, please let me know. Appreciate it!

  12. Prospectus Says:

    Thinkscripter has a community I think


  13. Binh Pham Says:

    How do I display a chartbubble at the beginning of the time window ?

  14. Prospectus Says:

    A bubble floating at the actual bar, or a label that sits in the corner of the window?


  15. don arthur Says:

    trying to make script that draws a line for the day on a 10 minute chart – between to price points i input = start at 930 ending 1550
    or from 1 inputted price and it calculates the final point based on formula at 1550

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: