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.
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);- Platform
- thinkorswim desktop Editor
- 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 desktop thinkScript Editor. The example above marks every bar above its average, not just the first crossover. No chart execution is claimed here.
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. For AddOrder scripts, use the Strategies tab.
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.
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.
thinkScript guides
Topic pages with copyable code
Each guide covers one thinkScript feature with a complete code example, platform steps, and official source links.
- Probability indicatorBuild a rolling historical up-rate study with 5, 10, and 20-bar labels.
- PaintingStrategy.HORIZONTALDraw horizontal segments for fixed price levels instead of connected lines.
- Tutorial and documentationStart with variables, plots, functions, and the official Learning Center path.
- ColorsUse Color constants, CreateColor, GetColor, and DefineColor in plots and labels.
- AddLabel and AsTextAdd chart labels and format numbers with AsText and NumberFormat constants.
- AddOrder and strategiesPlace simulated orders with AddOrder and OrderType constants for backtesting.
- Mark priceReference the mark price with PriceType.MARK and understand its chart limits.
Language building blocks
Core thinkScript concepts
| Concept | Keyword or function | What it does |
|---|---|---|
| Variable | def | Stores a calculated value for reuse in the script. |
| Input parameter | input | Exposes a configurable value in the study settings. |
| Visual output | plot | Draws a line, point, or histogram on the chart. |
| Historical offset | close[1] | References the value from a previous bar. |
| Chart label | AddLabel | Adds text to the chart with a condition and color. |
| Simulated order | AddOrder | Adds a backtest order when a condition is true. |
| Painting style | SetPaintingStrategy | Changes how a plot is drawn on the chart. |
| Color | Color constants | Sets plot, label, and background colors. |
Primary sources
Official thinkScript references
The thinkorswim Learning Center hosts the full language reference, tutorials, and function documentation.
- thinkScript TutorialsOfficial tutorial series covering variables, functions, plotting, and strategies.
- thinkScript ReferenceFunctions, constants, declarations, operators, and reserved words.
- thinkScript Q&AOfficial FAQ on how to start scripting and where to find help.
- Creating StrategiesTutorial chapter on AddOrder and backtesting strategies.
Frequently asked questions
What is thinkScript?
thinkScript is the built-in programming language for the thinkorswim platform. You write studies and strategies in the thinkScript Editor, and thinkorswim parses the source and renders plots, labels, alerts, and simulated strategy orders on the chart.
Is thinkScript the same as Pine Script?
No. Pine Script is the language used on TradingView. thinkScript is the language used in thinkorswim. They share some concepts like plots, inputs, and historical offsets, but the syntax, function names, and platform behavior differ.
How do I open the thinkScript Editor in thinkorswim?
Open the Charts tab, click Studies in the upper right, select Edit Studies, then click Create. The Editor window opens with a default plot Data = close line that you replace with your own source.
Do thinkScript chart strategies place live orders?
No. AddOrder in a thinkScript strategy adds simulated orders to the chart for backtesting. thinkorswim does not send those orders to a brokerage account. Review the strategy report and test assumptions before relying on results.
Where is the official thinkScript documentation?
The thinkorswim Learning Center hosts the thinkScript tutorials, function reference, constants, declarations, and reserved words. Use the entry for the specific function and the platform context you need.
Can Pineify write thinkScript for me?
Yes. The Pineify thinkorswim AI Coding Agent can draft editable single-file thinkScript studies and strategies from plain English. It does not compile or execute them in thinkorswim. You review the source in Pineify, then paste it into the thinkScript Editor and test it on a chart.
Write thinkScript without memorizing the syntax
Describe the study or strategy you need in plain English. The Pineify thinkorswim AI Coding Agent can draft an editable thinkScript file. Review the source, then paste it into the thinkScript Editor and test it on a chart.
This page is for educational and informational purposes. It does not provide investment advice, predict future prices, or guarantee trading results.