ad
ad
Topview AI logo

How to Automate Your Trading in ThinkorSwim (Thinkscript Tutorial - Full Series)

Gaming


Introduction

Part 1: Introduction to ThinkScript Coding Strategies

Welcome and Overview

In the first video of this mini-series, you're introduced to coding strategies in Thinkorswim, emphasizing the underutilization of code by retail traders. Almost all professional traders use some algorithmic form for trading or backtesting. This series focuses on backtesting, where you automate the entry and exit of trades based on objective rules.

Getting Started with ThinkorSwim

To begin, navigate to Studies > Edit Studies in Thinkorswim. Here, under the Strategies tab, you can create new strategies. This section comes with pre-existing strategies, identifiable by locked icons. For this tutorial, you will create a new strategy and learn the addOrder function, which executes trades based on your conditions.

Part 2: Implementing Studies into Your Strategy

Understanding Studies

Trading indicators are crucial because they help define entry and exit points. Most studies in Thinkorswim have default parameters and can be customized. You learn how to define parameters like RSI and Simple Moving Average (SMA).

Implementing Studies into Your Code

You’ll use different studies within ThinkScript by defining them above your main logic and then using these custom parameters in your buy/sell conditions. For instance, using RSI to make buy/sell decisions, and then refining those trades with additional criteria such as moving averages.

Part 3: Incorporating Price Action

Basic Price Action

Price action forms, such as bar opens, closes, highs, and lows, are integrated into your buy/sell strategies. For example, coding a buy condition to check if the close of the last bar is higher than the close of the bar before it can help identify price trends more accurately.

Advanced Use of Price Action

This section explains how to use price ranges to define buy and sell conditions, like identifying the highest high or lowest low over a specific number of bars. This helps you make trading decisions based on recent data trends, which can improve the backtesting results.

Part 4: Day Trading with Time Constraints

Adding Time Constraints

Day trading strategies typically don't hold positions overnight. You learn to code your strategy such that trades are only executed during specified trading hours. Parameters like market open and close times are defined and integrated into your buy and sell conditions.

Optimizing Time-Based Strategies

In incorporating time-based rules, you ensure that your strategy only works during market hours, avoiding holding trades overnight or entering trades during pre-market hours.

Part 5: Implementing Stop Losses

Importance of Stop Losses

Stop losses are essential in trading to protect against unexpected market movements. This segment shows how to code stop losses using both study conditions (like RSI) and price action (like lowest low).

Coding Stop Loss Conditions

By defining a stopLoss condition in your ThinkScript, you make sure your code has safety measures. This can prevent significant losses by exiting trades when the predefined stop-loss conditions are met.

Part 6: Backtesting Correctly

Common Pitfalls in Backtesting

The final video explains the pitfalls of backtesting, such as impossible trades, survivorship bias, and focusing only on total P&L. You learn the importance of ignoring impossible trade scenarios and validating your strategy across different market conditions.

Running and Analyzing Backtests

You use Thinkorswim’s on-demand feature to test your strategy across different periods. This validates the robustness of your strategy.


Keywords

  • ThinkorSwim
  • ThinkScript
  • Backtesting
  • Trading Algorithms
  • Day Trading
  • Strategies
  • Stop Loss
  • Price Action
  • Trading Indicators
  • Automated Trading

FAQ

What is ThinkorSwim?

ThinkorSwim is a trading platform provided by TD Ameritrade that allows traders to trade multiple asset classes, including stocks, options, and futures. It also offers powerful tools for technical analysis and backtesting.

What is ThinkScript?

ThinkScript is a scripting language used within ThinkorSwim to create custom studies, strategies, and alerts for trading.

How do you backtest a strategy in ThinkorSwim?

You backtest a strategy in ThinkorSwim by writing a script using ThinkScript, which includes your buy and sell conditions. You can then see the simulated trades on the chart and analyze the results using the on-demand feature.

What are some common pitfalls in backtesting?

Common pitfalls include testing impossible trades, falling victim to survivorship bias, and focusing solely on the P&L without considering other statistical measures like win rate and average profit per trade.

Why is having a stop loss important?

A stop loss is essential to protect your trading account from significant losses. It ensures that you exit a trade if the market moves against your position beyond a set threshold.

How can I ensure my backtest is robust?

To ensure your backtest is robust, test your strategy across multiple market conditions and time frames. Use Thinkorswim's on-demand feature to go back and simulate trades in different historic periods and under varying market conditions.