ThinkScript Tutorial: Master Custom Trading Indicators & Automated Strategies on Thinkorswim (2025 Guide)
Ever stared at your Thinkorswim charts wishing you could tweak that RSI indicator just a bit? Or dreamed of alerts that actually understand your trading style instead of firing every five minutes?
I get it. After years of trading, you realize the built-in indicators work fine for everyone else, but not quite right for your specific approach to the markets.
That's exactly why thinkScript exists—TD Ameritrade's programming language built right into Thinkorswim. It's like having a custom workshop where you can build indicators that think the way you trade. And here's the kicker: you don't need a computer science degree to use it.
Why ThinkScript Is Worth Your Time (Even If You Hate Coding)
Look, I'm not here to convince you that programming is fun. But thinkScript? It's different. It's less like coding and more like teaching your charts to speak your language.
Build indicators that actually fit your style: Tired of RSI(14) when you really need RSI(21) with custom overbought levels? Or maybe you want Bollinger Bands that adapt to market volatility? ThinkScript lets you build exactly what you need, not what everyone else uses.
Alerts that don't drive you crazy: Instead of getting pinged every time RSI hits 70, set conditions like "notify me when RSI crosses above 70 AND volume is 150% above average AND we're above the 20-day moving average." Now you're talking about setups that actually matter.
Backtest before you bet: This is huge. Build your strategy, run it against months or years of real market data, and see if it would've made money before risking your actual cash. It's like having a time machine for testing trading ideas.
Automated strategy execution: While thinkScript can't place trades without your approval, it can help you build automated trading strategies that alert you to perfect setups and even suggest position sizes based on your risk parameters.
ThinkScript Fundamentals: Start Here (Don't Overthink It)
Here's the thing about thinkScript—it's designed for traders, not computer programmers. The syntax reads almost like English, which means you can focus on your trading logic instead of wrestling with confusing code.
The Three Things You Actually Need
Variables: Think of these as labeled boxes for your data
def myMovingAverage = Average(close, 20);
def currentPrice = close;
Functions: Pre-built calculations that save you time
def highestHigh = Highest(high, 10);
def lowestLow = Lowest(low, 10);
Plotting: How you see your work on the chart
plot myIndicator = (currentPrice - myMovingAverage) / myMovingAverage * 100;
Real-World Example: Volume-Weighted Momentum Indicator
Let me show you something you can use today—a custom momentum indicator that combines price movement with volume analysis. This is the kind of tool that helps you spot moves before they happen:
def length = 14;
def priceChange = close - close[length];
def volumeAverage = Average(volume, length);
def volumeRatio = volume / volumeAverage;
def momentum = priceChange * volumeRatio;
plot CustomMomentum = momentum;
CustomMomentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
CustomMomentum.AssignValueColor(if momentum > 0 then Color.GREEN else Color.RED);
This isn't theoretical fluff—it's the kind of indicator that can spot momentum shifts before they show up in price action alone.
Your First Custom ThinkScript Indicator (Step-by-Step)
Forget those 47-page manuals. Here's how to build your first custom indicator in under 5 minutes:
- Right-click on any chart → "Studies" → "Edit Studies"
- Click "Create" → "Study" (not "Strategy" for now)
- Copy and paste this starter code:
# Basic RSI with custom levels
input rsiLength = 14;
input overbought = 75;
input oversold = 25;
def myRSI = RSI(length = rsiLength);
plot RSI_Line = myRSI;
plot Overbought_Line = overbought;
plot Oversold_Line = oversold;
RSI_Line.AssignValueColor(
if myRSI > overbought then Color.RED
else if myRSI < oversold then Color.GREEN
else Color.GRAY
);
- Name it something memorable like "MyCustomRSI" and hit OK
That's it. You've just built your first custom indicator that's more useful than half the stuff you'll find in most trading courses.
Advanced ThinkScript Techniques That Actually Matter
Smart Alerts That Filter Out Noise
Here's where most traders mess up—they set alerts that fire constantly. Instead, let's build alerts that matter:
# Alert only when conditions align
def priceAboveMA = close > Average(close, 20);
def highVolume = volume > Average(volume, 20) * 1.5;
def rsiOversold = RSI() < 30;
# This only triggers when ALL conditions are met
Alert(priceAboveMA and highVolume and rsiOversold, "High-probability bounce setup", Alert.BAR, Sound.DING);
Conditional Orders That Think
Want to set a buy order that only triggers when your custom indicator gives the green light? Here's how:
# Example for a conditional buy order
def buySignal = RSI() crosses above 30 and close > Average(close, 50);
# You'd use this in the order rules when setting up a conditional order
# buySignal becomes your trigger condition
Backtesting Strategies: The Smart Trader's Secret Weapon
This is where thinkScript becomes incredibly valuable. Before you risk a penny, you can test whether your trading ideas would've actually made money over the past year, two years, or even longer.
Strategy vs. Study: The Real Difference
- Studies show you information (like indicators)
- Strategies actually place virtual trades so you can see if you'd make money
Here's a simple moving average crossover strategy to test:
input fastLength = 9;
input slowLength = 21;
def fastMA = Average(close, fastLength);
def slowMA = Average(close, slowLength);
# This creates virtual trades
AddOrder(OrderType.BUY_AUTO, fastMA crosses above slowMA, close, 100, Color.GREEN, Color.GREEN);
AddOrder(OrderType.SELL_AUTO, fastMA crosses below slowMA, close, 100, Color.RED, Color.RED);
After you add this to a chart, Thinkorswim will show you exactly how much money this strategy would've made or lost, including win rate, maximum drawdown, and profit factor. It's like having a crystal ball for your trading ideas.
Professional ThinkScript Features for Serious Traders
Multi-Timeframe Analysis Made Simple
Want to see what the daily trend is while you're trading 5-minute charts? Here's how:
def dailyClose = close(period = AggregationPeriod.DAY);
def dailyMA = Average(close(period = AggregationPeriod.DAY), 20);
def trendAlignment = close > dailyMA;
plot DailyTrend = if trendAlignment then 1 else 0;
DailyTrend.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Smart Volume Analysis (Beyond Basic Volume Bars)
Forget staring at volume bars trying to guess what's normal. Build indicators that automatically identify when something unusual is happening in the market:
def volumeMA = Average(volume, 20);
def volumeRatio = volume / volumeMA;
def unusualVolume = volumeRatio > 2;
plot VolumeSpike = if unusualVolume then close else Double.NaN;
VolumeSpike.SetPaintingStrategy(PaintingStrategy.POINTS);
VolumeSpike.SetDefaultColor(Color.YELLOW);
Frequently Asked Questions About ThinkScript
"Can thinkScript actually place trades for me automatically?" Not exactly, and that's probably a good thing. Thinkorswim requires you to approve every trade, which keeps you in control while still giving you the benefits of systematic trading. Think of it as having an incredibly smart trading assistant who never sleeps but always asks for your permission before acting.
"I'm terrible with computers. Can I still learn this?" Absolutely. You don't need programming experience—just curiosity and patience. Start with the examples above, change a few numbers, and see what happens. The same way you might experiment with different RSI configurations, you can experiment with thinkScript by tweaking existing code.
"What's the difference between thinkScript and Pine Script?" Great question! Both let you build custom indicators, but thinkScript is TD Ameritrade's language while Pine Script is TradingView's. If you're curious about the differences, check out our guide on converting Pine Script to thinkScript—the logic is often similar, just different syntax.
"Where do I learn more without getting overwhelmed?" Start with TD Ameritrade's Learning Center, but honestly? The best approach is taking working examples (like the ones above) and modifying them for your specific needs. Like most algorithmic trading platforms, thinkScript makes more sense when you see it in action rather than reading manuals.
Your ThinkScript Action Plan (Start This Week)
- Test the custom RSI example above on a chart you trade regularly
- Modify one parameter—change the RSI length from 14 to 21 or adjust the overbought level from 75 to 80
- Build your first intelligent alert using the multi-condition example
- Backtest one simple strategy on historical data before putting real money on the line
- Join a trading community where you can share ideas and learn from other thinkScript users
Why ThinkScript Beats Generic Indicators Every Time
The beauty of thinkScript isn't just the customization—it's that you can build indicators that think the way you trade. No more forcing your strategy to fit someone else's indicator settings.
Start simple. Build complexity only when you need it. And remember: the best trading indicator is the one that helps you make money, not the one that looks the prettiest on your charts.
Whether you're building day trading indicators or complex multi-timeframe strategies, thinkScript gives you the tools to trade your way, not someone else's way.

