thinkorswim programming language

thinkScript

thinkScript is the built-in programming language for thinkorswim. You write studies and strategies in the thinkScript Editor, and the platform renders plots, labels, alerts, and simulated orders on the chart.

HelloWorldStudythinkScript
input length = 20;

def avg = Average(close, length);
def isAbove = close > avg;

plot SMA = avg;
plot Signal = if isAbove then close else Double.NaN;

SMA.SetDefaultColor(Color.CYAN);
Signal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal.SetDefaultColor(Color.GREEN);

AddLabel(yes, if isAbove then "Above SMA" else "Below SMA",
    if isAbove then Color.GREEN else Color.RED);
inputs
plots
labels
Platform
thinkorswim desktop and web
Output types
Studies, strategies, watchlist columns
Editor
Built-in thinkScript Editor

Direct answer

What thinkScript is and what it builds

thinkScript is a domain-specific language embedded in thinkorswim. You use it to create custom chart studies, backtesting strategies, watchlist columns, and conditional alerts. The language provides built-in access to price data (open, high, low, close, volume), technical analysis functions, and visual output controls.

A study calculates values and plots them on the chart. A strategy does the same and adds simulated orders with AddOrder so you can review a backtest report. Both are single-file scripts written in the thinkScript Editor.

01

Open the Editor

In thinkorswim, go to Charts, click Studies, select Edit Studies, then click Create to open the thinkScript Editor with a default plot.

02

Write or paste source

Replace the default line with your study or strategy. Use def for variables, input for parameters, plot for visual output, and AddOrder for simulated strategies.

03

Parse and add to chart

Let the Editor check the syntax. Resolve any messages, save the study, and add it to a chart to inspect the plots, labels, and strategy behavior.

Language building blocks

Core thinkScript concepts

ConceptKeyword or functionWhat it does
VariabledefStores a calculated value for reuse in the script.
Input parameterinputExposes a configurable value in the study settings.
Visual outputplotDraws a line, point, or histogram on the chart.
Historical offsetclose[1]References the value from a previous bar.
Chart labelAddLabelAdds text to the chart with a condition and color.
Simulated orderAddOrderAdds a backtest order when a condition is true.
Painting styleSetPaintingStrategyChanges how a plot is drawn on the chart.
ColorColor constantsSets plot, label, and background colors.

Frequently asked questions

Write thinkScript without memorizing the syntax

Describe the study or strategy you need in plain English. The Pineify thinkorswim AI Coding Agent generates a complete, editable thinkScript file. Review the source, then paste it into the thinkScript Editor and test it on a chart.

Open the thinkScript AI agent

This page is for educational and informational purposes. It does not provide investment advice, predict future prices, or guarantee trading results.