Thinkorswim, a powerful trading platform by TD Ameritrade, offers a robust scripting language called thinkscript. This language allows traders to create custom indicators, strategies, and other tools to enhance their trading experience. If you're new to thinkscript, exploring thinkorswim script examples can be a great starting point. Let's dive into some key aspects and examples to help you get started.

Thinkscript is designed to be user-friendly, with a syntax similar to C++, making it accessible to traders with varying programming backgrounds. It's essential to understand that thinkscript is not used for backtesting or live trading. Instead, it's used to create custom studies, strategies, and other visualizations that can aid in your trading decisions.

Thinkorswim Script Examples: Custom Indicators
One of the most common uses of thinkscript is creating custom indicators. Indicators help traders identify trends, momentum, and other market conditions. Let's look at two simple examples.

Moving Average Example
Thinkorswim already has built-in moving averages, but creating a custom one can help you understand the logic behind them. Here's a simple example of a 50-day moving average:

```thinkscript # Declare the input variable input length = 50; # Calculate the moving average def MA = average(close, length); ```
In this script, we first declare the input variable 'length', which is the number of periods (days, in this case) used to calculate the moving average. Then, we use the 'average' function to calculate the moving average of the closing prices over the specified length.
Relative Strength Index (RSI) Example
The RSI is a momentum oscillator that can help identify overbought or oversold conditions. Here's a simple RSI script:

```thinkscript # Declare the input variables input length = 14; input level1 = 30; input level2 = 70; # Calculate the average gains and losses def avgGain = average(change(close), length) / length; def avgLoss = average(change(close), length) / length; # Calculate the RSI def RS = 100 - (100 / (1 + avgGain / avgLoss)); ```
In this script, we first declare the input variables: the length of the RSI period and the overbought/oversold levels. Then, we calculate the average gains and losses using the 'change' function. Finally, we calculate the RSI using the formula: RSI = 100 - (100 / (1 + avgGain / avgLoss)).
Thinkorswim Script Examples: Custom Strategies
Thinkscript can also be used to create custom strategies. While these strategies can't be backtested or live-traded, they can provide valuable insights and help you understand how different strategies work.

Simple Moving Average Crossover Example
Here's a simple example of a moving average crossover strategy. This strategy generates a buy signal when the short-term moving average crosses above the long-term moving average and a sell signal when the short-term moving average crosses below the long-term moving average:



















```thinkscript # Declare the input variables input shortLength = 50; input longLength = 200; # Calculate the moving averages def shortMA = average(close, shortLength); def longMA = average(close, longLength); # Generate signals def buySignal = shortMA crosses above longMA; def sellSignal = shortMA crosses below longMA; ```
In this script, we first declare the input variables: the lengths of the short-term and long-term moving averages. Then, we calculate the moving averages using the 'average' function. Finally, we generate buy and sell signals using the 'crosses above' and 'crosses below' functions.
Bollinger Bandwidth Example
Bollinger Bands are a popular indicator used to measure volatility. Here's a simple example of a Bollinger Bandwidth strategy:
```thinkscript # Declare the input variables input length = 20; input multiplier = 2.0; # Calculate the Bollinger Bands def upperBand = average(close, length) + stdev(close, length) * multiplier; def lowerBand = average(close, length) - stdev(close, length) * multiplier; # Generate signals def buySignal = close crosses below lowerBand; def sellSignal = close crosses above upperBand; ```
In this script, we first declare the input variables: the length of the Bollinger Bands and the multiplier used to calculate the upper and lower bands. Then, we calculate the Bollinger Bands using the 'average' and 'stdev' functions. Finally, we generate buy and sell signals when the price crosses the lower and upper bands, respectively.
Exploring thinkorswim script examples is a great way to learn thinkscript and understand how different indicators and strategies work. As you become more comfortable with thinkscript, you can start creating your own custom tools to enhance your trading experience. Happy scripting!