Skip to main content

Supply Demand Edge Indicator for ThinkOrSwim (Free Download)

IndicatorFreeBeginner19 min video50 lines of codeJul 15, 2019

Our free Supply Demand Edge indicator for ThinkOrSwim plots an arrow when price makes a new high or low of the day that $TICK or $ADSPD does not confirm.

Supply Demand Edge on a ThinkOrSwim chart
On this page

Overview

In this tutorial I build the Supply Demand Edge indicator for ThinkOrSwim, a free study that looks for supply and demand imbalances using two market internals: the NYSE TICK ($TICK) and the advance/decline spread ($ADSPD). When price makes a new high or low of the day and one of those internals doesn't make a new extreme with it, the indicator draws an arrow on the chart.

This is Episode 4 of our How to thinkScript series. The indicator is for intraday traders who want ThinkOrSwim to watch the internals for them, on futures like the ES or on individual stocks, and who will use the arrows next to another tool they trust.

Key Takeaways

  • The Supply Demand Edge indicator compares price to two ThinkOrSwim market internals: the advance/decline spread ($ADSPD) and the NYSE TICK ($TICK).
  • A down arrow prints when a bar makes the high of the day but the internal's high on that bar is below its own high of the day. An up arrow runs the same test at the low of the day.
  • The study has 4 signals (A/D short, A/D long, TICK short, TICK long) and 2 inputs, showTicks and showAD, both set to yes by default.
  • In the downloaded version, advance/decline arrows are white and TICK arrows are red (short) or light green (long). The download is updated to work with extended hours on or off.
  • In the video, the advance/decline arrows tended to be a little more accurate than the TICK arrows, and a 15-minute chart gave fewer triggers and less noise.

What Is a Supply and Demand Edge?

A supply and demand edge comes from spotting an imbalance between buyers and sellers in the market. I treat the stock market as one big marketplace with buyers on one side and sellers on the other. The job is to work out whether it's a buyers' market or a sellers' market, and to do that you need a way to measure supply and demand.

The Two Market Internals Behind the Arrows

ThinkOrSwim has two built-in market internals for measuring supply and demand, and the Supply Demand Edge indicator reads both. The advance/decline spread tells you how many stocks are going up versus going down. The TICK measures how much buying or selling pressure there is, and how strong that pressure is.

InternalThinkOrSwim symbolWhat it measuresDivergence at a new low
Advance/decline spread$ADSPDHow many stocks are going up versus going downPrice makes a new low, but the number of stocks going down has dwindled
NYSE TICK$TICKHow much buying or selling pressure there is, and how strong it isPrice makes a new low, but selling pressure has stopped building or buying pressure has come in

In a normal market the internals move with price. As the market makes new lows, you'd expect more and more stocks to fall and selling pressure to keep building. When price makes a new low and the internals don't follow, that's a divergence you can take advantage of. The same idea applies in reverse at a new high.

Watching this by eye across a wide range of symbols all day isn't realistic. The indicator hands that work to ThinkOrSwim and marks each divergence with an arrow. For a closer look at reading these clues, see our research on NYSE TICK divergences between price and market internals.

What the Supply Demand Edge Indicator Plots

The Supply Demand Edge indicator plots up to 4 arrow signals on an intraday price chart. Short signals can only fire at the high of the day and long signals only at the low of the day. The table shows each plot as it appears in the downloaded code.

PlotFires whenArrowColor and weight in the downloadInput
ADShortSignalThe bar's high is the high of the day, and $ADSPD's high on the bar is below its high of the dayDownWhite, weight 1showAD
ADLongSignalThe bar's low is the low of the day, and $ADSPD's low on the bar is above its low of the dayUpWhite, weight 1showAD
TickShortSignalThe bar's high is the high of the day, and $TICK's high on the bar is below its high of the dayDownRed, weight 2showTicks
TickLongSignalThe bar's low is the low of the day, and $TICK's low on the bar is above its low of the dayUpLight green, weight 2showTicks

Read a down arrow this way: price made a new high of the day, but the internal is weaker than it was at its peak earlier in the session. An up arrow is the mirror image at the low of the day.

The 2 inputs, showTicks and showAD, default to yes and switch each pair of arrows on or off. I added them because the advance/decline arrows tended to be a little more accurate than the TICK arrows, and a setting is quicker than commenting out code.

How to Add the Indicator to ThinkOrSwim

The Supply Demand Edge indicator is a free download, and it runs on intraday charts.

  1. Download the .zip from this page. It holds one file, TI_SupplyDemandEdgeSTUDY.ts.
  2. Import the file as a study. Our guide on how to import a study into ThinkOrSwim walks through it.
  3. To build it yourself instead, click the Studies icon in the top right corner of a chart, choose Create new study, give it a name (I called mine supply demand edge), and paste in the code from the Code tab.
  4. Add the study to an intraday chart. The code includes declare hide_on_daily;, so it stays hidden on daily charts.
  5. Open the study's settings to set showTicks or showAD to no if you want only one set of arrows.

How the Code Works

The Supply Demand Edge code tracks 3 sets of running highs and lows through the session: one for price, one for $ADSPD and one for $TICK. Then it compares each bar's internal readings to those running extremes. The snippets below come from the downloaded version.

Step 1: Define the Regular Session

This step’s code is free with an account. Create one or sign in.

regularSession is true on bars after 0930 and before 1600, the market hours when $TICK and $ADSPD update. On the 0930 bar itself, secondsFromTime(0930) is 0, so the variable is false and every running high and low starts over from that bar. Our tutorial on how to set custom hours in thinkScript covers this kind of time filter.

Step 2: Track the High and Low of the Day

This step’s code is free with an account. Create one or sign in.

Inside the session, hod rises when a bar makes a new high of the day and otherwise keeps its last value. lod does the same with lows. Outside the session, both reset to the current bar.

In the video I wrote these lines with a same-day check. The logic is the same: a new high replaces the old one, and the first bar of the day sets the starting high and low.

Step 3: Do the Same for $ADSPD and $TICK

This step’s code is free with an account. Create one or sign in.

high(symbol="$ADSPD") reads the high of the advance/decline spread instead of the symbol on your chart. highAD and lowAD hold its high and low of the day. highTick and lowTick do the same with $TICK.

Step 4: Read the Current Bar's Internals

This step’s code is free with an account. Create one or sign in.

These 4 lines give the current bar's high and low for each internal, to compare against its high and low of the day.

Step 5: Write the Signals

This step’s code is free with an account. Create one or sign in.

ADShortSignal is true when showAD is on, the bar's high equals the high of the day, and $ADSPD's high on this bar is below its high of the day. Price is making new highs, but the number of stocks going up is dwindling.

ADLongSignal flips the comparisons: the bar's low is the low of the day, and $ADSPD's low is above its low of the day. The two TICK plots use the same tests with highTick and lowTick.

Step 6: Style the Arrows

This step’s code is free with an account. Create one or sign in.

SetPaintingStrategy turns each true/false plot into an arrow: BOOLEAN_ARROW_DOWN for the short signals and BOOLEAN_ARROW_UP for the long ones. I put the styling in the code so I set it once and never have to change it from the study screen again.

How the Download Differs From the Video

The downloaded Supply Demand Edge study is an updated version of the one I built on camera. The signal logic is the same. The file's header credits two contributors for the session and $TICK fixes, and the arrow colors changed too.

DetailBuilt in the videoDownloaded version
Session handlingSame-day check. Extended hours had to be turned off on the chart, or the study gave an errorregularSession check, which the header credits for working with extended hours on or off
$TICK linesBuilt by copying and pasting the A/D linesIncludes a fix for a $TICK copy-and-paste error in the original code
A/D arrowsGreen, weight 3White, weight 1
TICK arrowsCyan, weight 3Red for short and light green for long, weight 2

If you typed the code along with the video, compare your $TICK lines with the download.

Examples From the Video

The Supply Demand Edge indicator was tested on the ES, the Dow, Microsoft and Netflix in the video. These are the patterns I pointed out on the charts I had up that day.

The ES and the Dow

On the ES, divergence arrows started to show up, and then price reached a Volatility Box level, which gave the entry. The A/D divergences kept stacking up, and price then dropped hard. The same thing happened again later on the chart: divergences stacked up, and price dropped.

On the Dow, a TICK arrow in the morning pointed long. Later, A/D divergences built up as price moved closer to the Volatility Box, and price then went straight down. Each divergence got a reaction, which is what I look for. How far price follows through depends on how strong the divergence is.

Friday was the counterexample. The market gapped up and kept rising, and none of the arrows had strong follow-through. On a day like that, the divergences were good for scalps. On other days, the divergences made good trades on their own, especially next to the Volatility Box.

Microsoft on a 15-Minute Chart

The indicator runs on stock charts too, and you can change the timeframe. Moving out to a 15-minute timeframe gives fewer triggers and less noise, so I looked at Microsoft on 15-minute bars. Divergence arrows came before drops, and TICK arrows came before moves up. One TICK arrow was a false signal, while the divergence arrows on that chart worked.

Netflix

I picked Netflix because it carries less weight in the market than Microsoft, to see if the signals still worked. A TICK arrow came first and was a false signal. The A/D arrow after it gave a much better entry. Another A/D arrow pointed long and got a small move up.

At the next day's open, the first arrows were false signals that came a little too early, though price did move up afterward. Then down arrows pointed short, and price followed through a long way.

How I Use the Signals

I use the Supply Demand Edge indicator as an assistant to one or two other tools that give me an edge, like the Volatility Box levels in the examples above. Some arrows are false signals. The more charts you study, the better you get at telling strong divergences from weak ones.

It also fits reversion-to-the-mean trading. If you trade around a moving average, a divergence can be the sign that price is coming back to the mean before the trend continues. For a setup built on one moving average, see our Reversion to 50-Day Moving Average tutorial.

Treat an arrow as a read on the internals, and wait for your other tool to agree before you act. Decide where your stop goes first, and size the trade so a stop-out costs a small, fixed share of your account.

Other Ways to Track Market Internals

The Supply Demand Edge indicator checks the internals against price one bar at a time. If you'd rather watch the internals themselves, our Cumulative TICK indicator keeps a running total of the TICK through the day. The Extreme TICK Counter counts +1,000 and -1,000 TICK readings each day, and the Cumulative Advance Decline Trading System turns a cumulative advance/decline line into a trading system.

Common Problems

  • No arrows on a daily chart. The study is declared hide_on_daily. Switch to an intraday timeframe.
  • No arrows before the open or after the close. Outside the 0930 to 1600 window in the code, the running highs and lows reset on every bar, so no signal can fire. The 0930 bar never shows an arrow either.
  • An error with extended hours on. The version I typed in the video needed extended hours off. Import the download, which has the regularSession check.
  • Only one kind of arrow shows. Check that showTicks and showAD are both set to yes.
  • Too many arrows. Move to a larger timeframe or turn off the TICK arrows. In the video, a 15-minute chart gave fewer triggers and less noise.

Full thinkScript code

Supply Demand Edge.tsthinkScript · 50 lines
The full code is free with an account

Create a free account or sign in to copy all 50 lines and download the file.

Download

Supply Demand Imbalance Indicator

Download the Supply Demand Edge indicator for ThinkOrSwim. The download is a .zip with one study file, TI_SupplyDemandEdgeSTUDY.ts. It is the updated version of the code from the video, with the regular-session check that lets it run with extended hours on or off and the fix to the $TICK lines. If you haven't added a custom study before, here's how to import an indicator into your ThinkOrSwim platform.

Download free

Video: Supply Demand Edge, built line by line

19 minutes on YouTube.

Watch on YouTube

Questions

What does the Supply Demand Edge indicator do?

It marks divergences between price and two market internals, the NYSE TICK and the advance/decline spread. When a bar makes the high of the day but an internal is below its own high of the day, it plots a down arrow. At the low of the day, an internal holding above its low plots an up arrow.

How do I add the Supply Demand Edge indicator to ThinkOrSwim?

Download the free .zip from this page and import the TI_SupplyDemandEdgeSTUDY.ts file as a study. To build it by hand, click the Studies icon in the top right corner of a chart, choose Create new study, and paste in the code from the Code tab. Use an intraday chart.

What do the arrow colors mean in the Supply Demand Edge indicator?

In the downloaded version, white arrows come from the advance/decline spread. A red down arrow is a TICK short signal and a light green up arrow is a TICK long signal. In the video I used green for the advance/decline arrows and cyan for the TICK arrows, so the video colors differ from the download.

What is $ADSPD in ThinkOrSwim?

$ADSPD is the ThinkOrSwim symbol for the advance/decline spread, which shows how many stocks are going up versus going down. The Supply Demand Edge indicator reads its high and low on every bar, so it can compare market breadth to price on whatever chart you have open, whether that is a futures contract or a single stock.

Should I use the TICK signals or the advance/decline signals?

In my testing, the advance/decline arrows tended to be a little more accurate than the TICK arrows. That is why the study has the showTicks and showAD inputs. Set showTicks to no in the settings if you want only the advance/decline arrows, or leave both on and compare them on your own charts.

Does the Supply Demand Edge indicator work on futures and with extended hours?

Yes. In the video I ran it on the ES and the Dow as well as Microsoft and Netflix. $TICK and $ADSPD only update during market hours, and the version I built on camera needed extended hours turned off. The downloaded version adds a regular-session check, which its header credits for working with extended hours on or off.

Why don't I see any arrows from the Supply Demand Edge indicator?

Check four things. The study hides itself on daily charts, so use an intraday timeframe. Both inputs, showTicks and showAD, need to be set to yes. Arrows only print inside the 0930 to 1600 session window in the code. And an arrow needs a bar that makes a new high or low of the day while an internal lags, so a session with no divergence shows no arrows.

What timeframe works best for the Supply Demand Edge indicator?

It is built for intraday charts and hides itself on daily charts. In the video, moving a Microsoft chart out to 15 minutes gave fewer triggers and less noise. Pick the timeframe that matches how long you hold a trade, and expect more arrows and more noise on smaller bars.

Get each new indicator by email

One email on Sundays with the week's new tool and its code. A free account also unlocks every .txt download.

No credit card. Unsubscribe anytime.