Skip to main content
On this page

How to Use thinkScript: Studies, Alerts, and Strategy Tests

· 5 min read
Pineify Team
Pine Script and AI trading workflow research team

thinkScript is the scripting language in Schwab's thinkorswim platform for custom studies, scans, alerts, and strategy simulations. A chart strategy's hypothetical orders are not an autonomous live trading bot. Start by checking a simple study's output, then add one rule at a time.

ThinkScript

Create and inspect a small study​

In thinkorswim desktop, open Charts → Studies → Edit Studies, choose Create, and give the study a descriptive name. Start with a moving average before combining several signals:

input length = 20;
plot SMA = Average(close, length);

Use a positive length, save the study, and add it to the chart. Compare several values with the arithmetic mean of the corresponding closing prices. Average() calculates a simple moving average, not an EMA. Schwab's Average reference documents that calculation. An exponential average uses a different function and weighting rule.

This small example is a calculation exercise, not a buy/sell system. Check it in your own desktop editor before building on it; this article does not report a platform execution test or measured performance result.

Define signals precisely​

A condition such as “RSI below 30” remains true on every qualifying bar. A crossing condition describes the transition through a threshold. Decide which behavior you want before adding arrows or alerts, and specify whether the developing bar may change the result.

For built-in studies, inspect their parameter names and output plots in the official reference. Named parameters reduce the chance of passing a price series into a length or average-type parameter. A volume spike does not identify an institution, and an oversold reading does not guarantee a bounce.

Use appropriate painting strategies for arrows. A Boolean plot alone does not automatically become a price-anchored arrow. Confirm pane placement, scale, and missing values when a study looks blank or distorted.

Understand alert frequency​

The Alert() function takes a condition, message, alert type, and sound. Alert.BAR permits an alert once per bar; it does not automatically require the condition to have been false on the previous bar, nor does it by itself mean “at bar close.” See Schwab's Alert documentation.

If you want only a new transition, express that transition in the condition. If you add a session filter, check the time function's documented timezone and aggregation behavior rather than assuming the computer's local time. Test the actual notification channel and avoid treating a chart-study alert as a guarantee of delivery while every application is closed.

Separate strategy simulation from execution​

AddOrder() adds a hypothetical strategy order for the next bar when its condition is true. Its price and size arguments affect the simulated result; changing them can create assumptions that would not be achievable live. The default price is the next bar's open, as described in AddOrder.

Schwab's strategy tutorial explains backtesting with these signals. Adding a strategy to a chart does not route its orders to a brokerage account. Broker conditional orders are a separate workflow with their own supported conditions and restrictions.

Before interpreting a report, record the symbol, aggregation, available history, order timing, size, costs, and settings. Review individual trades. A high win rate can coexist with losses if losing trades are larger, and repeatedly tuning a rule on the same sample can overfit it.

Avoid misleading technical shortcuts​

  • A calculation using the current chart's close is not daily analysis unless the chart is daily or a daily aggregation is explicitly requested.
  • VWAP is not a volume-profile distribution; naming it “volume profile” changes neither its inputs nor its meaning.
  • Guard a zero denominator and choose a meaningful missing-value policy. Returning zero may create a false signal rather than solve the underlying data problem.
  • Keep explanatory labels distinct from numeric series. Use text expressions in functions that accept strings rather than assuming a numeric def can hold arbitrary text.

Build a reproducible learning sequence​

Verify the simple study, add one clearly defined signal, test its alerts, and only then define a strategy's entries and exits. Reserve observations outside parameter selection and keep failed variants in the record. A weekend of development or an arbitrary number of demo signals is not proof of readiness for live trading.

Pine Script uses related charting concepts but different APIs and execution rules. The Pine beginner's guide can help compare approaches; source code must be translated and validated for the target platform.

Does thinkScript AddOrder place live trades?

No. It adds hypothetical orders to a chart strategy. Live order submission is a separate brokerage workflow.

Does Average calculate an EMA?

No. It calculates a simple arithmetic moving average over the specified bars.

Does Alert.BAR mean a new crossing at bar close?

No. It limits alert frequency to once per bar. The signal definition and its evaluation timing must be handled separately.

The Best Pine Script Generator