How to get started with Thinkscript?
To get started with Thinkscript, you will first need to download the app. In order to do this, go over to the following link and select your OS. Then click “install thinkorswim” and follow the installation instructions.
While you wait for the program to download and install, go over to the following link and in the upper-right corner click the green “Open New Account” sign.
After that, be sure to go over the sign-up steps in order to properly create an account. When done, open your thinkorswim app and log in with your account credentials. Then you will need to accept the ToS.
Note: when logging in you can choose if you want to use Live Trading or Paper Money.
Thinkscript main layout
On the main toolbar that is situated on top of your interface, you can find the main windows. Each of the windows has its own (sub)toolbars. Let’s go over what each of the main windows represents:
- Monitor – tracks your trading activity and includes trading data like orders, balances, trading account status, statements, and more.
- Trade – contains interfaces that categorize the tradable assets, i.e. Forex, Futures, Pairs, and more.
- Analyze – has a plethora of analysis models that you can run in real, “what if” and backtesting scenarios.
- Scan – this serves as a filter with which you can hone in on your assets of interest.
- MarketWatch – provides you with useful market data
- Charts – provides a graphical interface for real-time data
- Tools – has several custom thinkorswim features.
To start scripting go to the Charts window, select a symbol from the symbol table, click “Studies” in the upper right corner, select “Edit Studies” and then click “Create”.
If this looks overwhelming to you, you are not the only one and by the end of this article, you will understand the basic components and available features of this program.
How to use Thinkscript fundamentals?
Thinkscript fundamentals can be seen as your basic building blocks. For example, in the opened script screen you can change the green “close” into an “open” to see the change in your graph.
Have in mind that you need to press “OK” in the down right corner of your script interface to create the script. Then click apply and you will see a blue line that appeared on your chart.
To go back into the editing mode, find your study in the left “Studies” panel. If you didn’t name it, the name should be “NewStudy0”. To open the script right-click on its name and press “Edit”
How to use Thinkscript Declarations?
Thinkscript declarations need to be initialized with the
declare command. For example, let us use the
upper declaration to create a price oscillator for our closing BTC values.
We will to this by having the
upper declaration place a weighted moving average plot on our main BTC chart.
declare upper; input price = close; input length = 9; plot AvgWtd = wma(price, length);
P.S. if you click apply in the scripting mode you can see a glimpse of your main chart but to see it in its full glory you’ll need to close the scripting interface.
How to use Thinkscript functions?
In order to use Thinkscript functions you will need to navigate to their respective drop menu that is found on the right side of your scripting station. When there you can easily explore the available functions.
For an example, let us create an exponential moving average on our BTC data:
input additionalBars = 0; plot ExpAvg = EMA2(close, additionalBars, 0.2);
I will also add an implied volatility graph that will appear in the lower section on the main Graph window:
declare lower; plot ImpliedVolatility = imp_volatility();
How to use Thinkscript Constants?
To use Thinkscript constants all you need to do is to define them prior to their use in your scripts. To define a constant you can use the
def command that is followed up by your custom constant name.
For our BTC chart, we will add a constant that will aggregate the candles by month and print out the closing prices for monthly periods.
def agg = AggregationPeriod.MONTH; plot data = close(period = agg);
How to set Alerts with Thinkscript?
To set an alert with Thinkscript you will need to use the Alert() command inside of which you specify the condition, text, alert type, and sound. There are different alert types that you can set and they are the following:
- Alert.BAR – triggers only once per bar
- Alert.ONCE – triggers only once after adding the study
- Alert.TICK – triggers on each alert tick
The sounds that are available for you alerts are chimes, bells, dings, rings, or soundless.
Now, let’s create an alert that will notify us when the asset reaches the closing price of $300. We’ll want the alert to display a message, alert us on each tick and do a ding sound.
Alert(open == 300, "Open price reached $300!", alert.TICK, Sound.Ding);
How to add simulated trades in Thinkscript?
To add a simulated trade in Thinkscript, you will go to the Analyze window and then select the “Add Simulated Trades” button. Then select the asset you would want to trade. I’ll go for the Google stock.
To simulate a trade just click on the Bid to sell, or to the Ask to buy, and underneath your orders will appear where you will be able to set up the number of shares.
To step up the game, you can click on a specific time period and change the calls by adding different strike values, custom quotes, instrument details, and much more.
How to place orders with Thinkscript?
To place an order with Thinkscript, all you need to do is to go over to the Trade window where you can select your asset and then buy or sell it by clicking the Bid and/or Ask buttons.
As you have clearly noticed, the interface looks the same as in our previous simulated trading demonstration. This was done by the developers to not induce confusion in the users.
To place an order via code you will need to use the following function:
AddOrder(type, condition, price, tradeSize, tickColor, arrowColor, name);
How to create your own strategy with Thinkscript?
Now that we have grasped the basics behind Thinkscript, we are ready to create a simple trading strategy. For this, we will use the Dropbox asset. We will want to buy when the asset crosses above the 20 SMA and vice versa.
Each time the asset crosses the 20 SMA we will be notified by an alert. The buy orders will be displayed in green while the sell order will be displayed in red. We will only want to buy 20 shares of the stock upon each cross.
input price = close; input length = 20; def AVG = Average(price, length); Alert(AVG < price, "The closing price is bellow the 20 SMA: "+price, alert.TICK, Sound.Ding); Alert(AVG > price, "The closing price is above the 20 SMA: "+price, alert.TICK, Sound.Ding); AddOrder(OrderType.BUY_AUTO, price crosses above avg, open[-1], 20, Color.GREEN, Color.GREEN, “Buy”); AddOrder(OrderType.SELL_AUTO, price crosses below avg, open[-1], 20, Color.RED, Color.RED, “Sell”);
Now that the strategy is done, we can apply it and check for its performance by right-clicking the signal and selecting “Show report”.