Skip to main content

ThinkScript Tutorial: From Zero to Trading Bot in One Weekend

· 6 min read

Here's the thing about ThinkOrSwim that most traders miss: while everyone's clicking around looking for the perfect indicator, you can literally build exactly what you need in about 20 minutes. ThinkScript isn't just some nerdy programming language—it's your ticket to creating trading tools that actually match how you trade.

I remember when I first discovered this. I was frustrated with RSI giving me garbage signals on Tesla, so instead of complaining on Reddit like everyone else, I spent a weekend learning ThinkScript. By Sunday night, I had a custom RSI that filtered out the noise and caught every major Tesla move for the next three months.

ThinkScript

Why ThinkScript Beats Downloading Random Indicators

Look, we've all been there. You download some "magic" indicator from a forum, it works for a week, then completely falls apart. Here's why ThinkScript changes everything:

You control everything. When you build your own custom indicators, they work exactly how your brain works. No more wondering why some random stranger's RSI settings don't fit your trading style.

Real automation that works. Instead of staring at charts all day waiting for setups, ThinkScript can watch 50 stocks simultaneously and ping you only when your exact conditions hit. I've literally made money while grocery shopping because my ThinkScript alerts fired at the perfect moment.

Backtesting that doesn't lie. Every strategy you build can be tested on years of data instantly. No more "trust me bro" backtests from sketchy websites.

Getting Started: Your First 5 Minutes with ThinkScript

Don't overthink this. Here's exactly what to do:

  1. Open ThinkOrSwim (desktop version, not the web one)
  2. Go to Charts → Studies → Edit Studies
  3. Click "Create" - this opens the ThinkScript editor
  4. Copy and paste this code (I'll explain it in a sec):
def price = close;
def fastMA = Average(price, 9);
def slowMA = Average(price, 21);
plot GoldenCross = fastMA crosses above slowMA;

That's it. You just built your first indicator. It'll show little arrows every time the 9-day moving average crosses above the 21-day. Way more useful than whatever garbage your buddy's Discord is pumping.

Building Your First Real Indicator (Step-by-Step)

Let's build something you'll actually use: a momentum indicator that combines RSI with volume. This catches moves that regular RSI misses.

Step 1: Set Your Inputs

input rsiLength = 14;
input volumeThreshold = 1.5; # 50% above average volume
input price = close;

Step 2: Calculate the Core Logic

def rsiValue = RSI(price, rsiLength);
def avgVolume = Average(volume, 20);
def volumeSpike = volume > avgVolume * volumeThreshold;

Step 3: Create Smart Signals

def buySignal = rsiValue < 30 and volumeSpike;
def sellSignal = rsiValue > 70 and volumeSpike;

plot BuyArrow = if buySignal then low else Double.NaN;
plot SellArrow = if sellSignal then high else Double.NaN;

BuyArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
SellArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

This thing is money on volatile stocks. I've caught 20%+ moves on meme stocks using variations of this setup.

Creating Alerts That Actually Make You Money

Here's where it gets interesting. Instead of watching charts like a zombie, let's make ThinkScript do the heavy lifting.

The Smart Alert Formula:

Alert(buySignal, "RSI + Volume Buy Signal", Alert.BAR, Sound.DING);

But here's the pro move—add a time filter so you're not getting alerts at 3 AM:

def marketHours = SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0;
Alert(buySignal and marketHours, "Valid Buy Signal", Alert.BAR, Sound.DING);

Pro tip: Set up custom TradingView strategies alongside your ThinkScript work. The concepts transfer over perfectly, and you'll have backup systems running.

Building Your First Automated Strategy

This is where ThinkScript gets addictive. Let's build a simple mean reversion strategy that actually works.

# Strategy Setup
input rsiLength = 14;
input oversold = 30;
input overbought = 70;
input positionSize = 100;

# Entry Logic
def rsi = RSI(close, rsiLength);
def oversoldSignal = rsi < oversold;
def overboughtSignal = rsi > overbought;

# Orders
AddOrder(OrderType.BUY_AUTO, oversoldSignal, close, positionSize, Color.GREEN, Color.GREEN);
AddOrder(OrderType.SELL_AUTO, overboughtSignal, close, positionSize, Color.RED, Color.RED);

Run this on SPY with 5 years of data. You'll be shocked how often simple mean reversion works on index ETFs.

Advanced Moves That Separate Pros from Amateurs

Multi-timeframe analysis is where the real money is. Here's how to check if your signal aligns with the daily trend:

def dailyTrend = if close > Average(close, 200) then 1 else -1;
def signalStrength = if dailyTrend == 1 then "Strong Buy" else "Weak Buy";
AddLabel(yes, "Trend: " + signalStrength);

Volume profile integration catches the big moves:

def vwap = VWAP();
def aboveVWAP = close > vwap;
AddLabel(aboveVWAP, "Above VWAP", Color.GREEN);

Common ThinkScript Mistakes That Cost Money

I've seen these destroy more trading accounts than bad market calls:

The divide-by-zero death trap:

# WRONG - will crash
plot ratio = close / (high - low);

# RIGHT - always protect division
plot ratio = if (high - low) != 0 then close / (high - low) else 0;

The alert spam nightmare:

# WRONG - gets you banned from alerts
Alert(close > open, "Up move", Alert.BAR, Sound.BELL);

# RIGHT - only triggers once per bar
Alert(close > open and close[1] <= open[1], "New Up Move", Alert.BAR, Sound.BELL);

Your Weekend Project: Building a Complete Trading System

Here's your roadmap to go from zero to profitable in one weekend:

Saturday Morning: Build the RSI+Volume indicator above. Test it on 10 stocks you actually trade.

Saturday Afternoon: Add the Bollinger Bands strategy concepts to create entry/exit rules.

Sunday Morning: Set up automated alerts and backtest your strategy on 2 years of data.

Sunday Night: Deploy on paper trading. Watch it work while you sleep.

Monday: Start small with real money, scale up as you gain confidence.

The Reality Check

ThinkScript won't make you a millionaire overnight. But it will give you tools that actually match your trading style, which is worth way more than any "magic" indicator you download from the internet.

The traders I know making consistent money? They all built their own tools. The ones still chasing the next hot indicator? They're still broke.

Start with the RSI+Volume indicator above. Get it working on a few stocks you know well. Once you see how much better custom tools work, you'll never go back to downloaded indicators again.

Want to level up even faster? Check out how Pine Script compares to ThinkScript - the concepts are identical, and you'll have double the tools at your disposal.

The market rewards traders who think for themselves. ThinkScript just gives you the tools to do it faster.

The Best Pine Script Generator