# Custom Candlestick Pattern Indicator for ThinkOrSwim (Free Code)

thinkScript tutorial Free Beginner 10 min video 18 lines of code Dec 10, 2023 Updated Oct 21, 2026

Code a custom candlestick pattern in ThinkOrSwim: a green candle with a lower low after a red one and a lower wick 4x its upper wick, marked with an arrow.

## Overview

In this tutorial I show you how to build a custom candlestick pattern indicator in ThinkOrSwim, starting from a bullish reversal candle I spotted 3 times on a chart of Microsoft. We pull observations out of the pattern, turn each one into a line of thinkScript, and end with an arrow under every candle that matches.

It's a beginner-friendly lesson, so you don't need any thinkScript experience. Along the way you learn how to measure a candle's upper and lower wicks, how to test each condition as you go, and how to combine several true/false conditions into one signal.

## Key Takeaways

- The custom candlestick pattern in the video is a bullish reversal candle: a green candle that makes a lower low than the candle before it, where that previous candle is red.

- The candle also needs a long lower wick. The code measures it as open - low, measures the upper wick as high - close, and requires the lower wick to be at least 4 times the upper wick.

- All 3 conditions are true/false variables joined with and in one plot signal line, so the study returns 1 when the pattern appears and 0 when it doesn't.

- While building, declare lower shows the result as a 0/1 line in a lower panel. Each new condition should cut the number of 1s.

- The finished study plots an up arrow under each match with PaintingStrategy.BOOLEAN_ARROW_UP at line weight 5.

## The Candlestick Pattern in the Video

The custom candlestick pattern in this video is a bullish reversal candle with a long lower wick. On the Microsoft chart in the video, I marked 3 examples of it. It's a basic pattern, and if you've traded for a while you've probably seen it many times, both on daily charts and on intraday charts.

Looking at the candle, 3 things stand out. It's green. It dips below the previous candle's low before coming back to close green, and that previous candle is red. And it has a long wick to the downside, much longer than the wick on top.

The shape is close to what many traders call a hammer. The textbook hammer is defined by a lower wick at least 2 times the candle's body and little or no upper wick. The rules in this video measure something different: the lower wick against the upper wick, plus a lower low after a red candle.

For the step-by-step process of turning any pattern's rules into code, see our companion lesson on [how to turn candlestick patterns into code](https://tosindicators.com/thinkscript/how-to-turn-candlestick-patterns-into-code).

## From Chart Observations to Conditions

A custom candlestick pattern study is a set of true/false conditions, one for each thing you can see on the candle. This table maps each observation to the variable and code that capture it:

What I see on the chart Variable thinkScript

The candle is green greenCandle close > open

It makes a lower low, and the previous candle is red previousCandleLow low < low[1] and close[1] < open[1]

The wick on top, on a green candle upperWick high - close

The wick underneath, on a green candle lowerWick open - low

The lower wick is long compared with the upper wick wickCondition lowerWick >= 4 * upperWick

The [1] after a price means "one bar ago", so low[1] is the previous candle's low. Each variable equals 1 when its condition is true and 0 when it isn't.

## How to Create the Study in ThinkOrSwim

The custom candlestick pattern study starts as a blank study, and you build it one condition at a time. These are the steps I follow in the video:

- Click the Studies icon on your chart, then Create to open the thinkScript editor.

- Move the editor to the side so you can see an example of the pattern on the chart while you write.

- Add the first condition with declare lower and a test plot, then click OK and Apply.

- Add one condition at a time to the plot signal line, applying after each one to check the result.

- When only the pattern candles return 1, remove declare lower and turn the plot into arrows.

The first condition is the candle's color, so that's where the code starts.

## The Code, Step by Step

The custom candlestick pattern code grows in 4 steps. After each one, I click Apply and look at what changed on the chart. I call this incremental testing in the video: test each observation as you add it, then adjust it if the results look wrong.

### Step 1: A Green Candle, Tested on a Lower Panel

(This step's code is free with an account.)

def greenCandle is true when the close is above the open. declare lower puts the study in a panel under the chart, where the line moves between 0 (false) and 1 (true). Every time it jumps to 1, there's a green candle above it. That's a lot of 1s, and the next steps narrow them down to the pattern.

### Step 2: A Lower Low After a Red Candle

(This step's code is free with an account.)

I first called this variable lowerLow , then renamed it previousCandleLow once it also checked the previous candle's color. It's true when this candle's low is below the previous low and the previous candle closed below its open. After I added it to the signal and clicked Apply, the number of 1s dropped sharply. The pattern candle still returned 1, along with some candles I didn't want.

### Step 3: Measure the Upper and Lower Wicks

(This step's code is free with an account.)

Measuring the wicks is the trick in this video. Since we already know the candle is green, it closed above where it opened. So the upper wick is the high minus the close, and the lower wick is the open minus the low. The wick condition then asks for a lower wick at least 4 times the upper wick.

On my first try I forgot to add wickCondition to the signal line, so I added it and applied again. Once it was in, the number of 1s dropped sharply again, to the kind of candles the pattern is about.

### Step 4: Turn the 0/1 Line Into Arrows

(This step's code is free with an account.)

Delete declare lower so the study moves back onto the price chart. Because signal is a Boolean, returning only 1 or 0, the BOOLEAN_ARROW_UP painting strategy paints an up arrow at the lower end of every candle where it's 1. Line weight 5 makes the arrows bigger and easier to see. The full study is in the Code tab on this page.

## What the Signals Looked Like on Microsoft

The finished study marked the kind of candle I was after on the Microsoft chart. One match came at the beginning of 2023, and it had the shape I was looking for. The candle I'd highlighted at the start of the video also still returned true with all 3 conditions in place.

Another match met every condition but didn't pinpoint the reversal as well. That's a useful lesson in itself: this is not a perfect reversal signal. What the code does well is show you, in seconds, every place this exact set of rules triggered, so you can judge them yourself.

## Ways to Customize the Pattern

The custom candlestick pattern has 2 settings in the code worth changing, plus 2 edits I'd suggest that aren't in the video:

Setting In the video What changing it does

Wick multiplier 4 * upperWick A lower number allows shorter lower wicks and gives more arrows. A higher number gives fewer.

Arrow size SetLineWeight(5) Sets how big the arrows are.

Zero upper wick (suggestion) Not handled A green candle that closes at its high has an upper wick of 0, so any lower wick passes, even 0.

Bearish version (suggestion) Not built Mirrors each condition to mark red candles with a long upper wick.

To make the zero-wick case require a real lower wick, add one more check to the wick condition:

(This step's code is free with an account.)

For a bearish version, flip each condition. A red candle's upper wick is the high minus the open, and its lower wick is the close minus the low. This is my suggestion for the mirror image, which the video doesn't build:

(This step's code is free with an account.)

## Where to Use the Signal Next

A custom candlestick pattern signal is a starting point for other tools. Once the pattern is one signal variable, you can plug it into an indicator, a scan, an automated trading order or a backtester. Our [candlestick automated trading example](https://tosindicators.com/automated-trading/candlestick) shows a candle condition triggering an order, and the [beginner's guide to automated trading](https://tosindicators.com/automated-trading/basics) covers the setup.

To count how many times the pattern fired on a chart, wrap the signal in TotalSum and print it with AddLabel, as in our [AddLabel tutorial](https://tosindicators.com/thinkscript/labels). Our [Candle Counter indicator](https://tosindicators.com/indicators/candle-counter) is another free study built from candle colors, if you want to see more of this kind of code.

## How I Use a Pattern Like This

The arrow marks a candle that matches a set of rules. Each arrow is a candidate to check on the chart. It doesn't tell you the reversal will hold, and the video shows a match that didn't pinpoint the turn. I use the arrows to find candidates quickly, then look at the chart and the levels around each one before deciding anything.

If you trade a match, decide the stop first and size the position so a stop-out costs a small, fixed share of your account. If the code throws an error while you build it, our guide on [how to fix bugs in thinkScript code](https://tosindicators.com/thinkscript/fix-bugs) walks through the usual fixes, and you'll find more lessons on the [thinkScript tutorials page](https://tosindicators.com/thinkscript).

## The pattern on real charts

Drawn from real daily bars with the code on this page, through Oct 20, 2026. The pattern from the code: a green candle that makes a lower low than a red candle before it, with a lower wick (open minus low) at least 4 times its upper wick (high minus close). Note the edge case in the code: a green candle that closes at its high has no upper wick, so any lower wick passes.

### MCD, Oct 12, 2026: the bullish pattern

MCD on Oct 12, 2026: the larger arrow is this signal; smaller arrows are other signals in view.

MCD closed at $235.68 on the signal and $242.63 5 trading days later, +2.9%. This is the most recent bullish signal on a well-known name that moved the way the pattern points. Most signals are less tidy: see the numbers below.

### By the numbers

9,724 Bullish signals

51.4% Higher 5 days later (any day: 52.1%)

+0.14% Typical 5-day move after a signal

1 in 40 Daily bars that print it

Every daily bar of our 648 stocks and ETFs from Nov 5, 2015 to Oct 20, 2026: the 14 ETFs from November 2015, most stocks from July 2024. "Any day" is every day in the same symbols. A pattern that does no better than that needs context from somewhere else on the chart.

The full thinkScript code is free with an account: [create one](https://tosindicators.com/register) or [sign in](https://tosindicators.com/login) on this page.

## Download

Custom Candlestick Patterns Download Custom Candlestick Patterns for ThinkOrSwim.

[Download free](https://tosindicators.com/thinkscript/custom-candlestick-patterns)

## Video: Custom Candlestick Patterns, built line by line

10 minutes on YouTube.

[Watch on YouTube](https://www.youtube.com/watch?v=YLFsYaWRVLg)

## Questions

How do I code a custom candlestick pattern in ThinkOrSwim?

Write down what you see on the candle, then turn each observation into a true/false def variable, such as def greenCandle = close > open;. Join them with and in one plot signal line, test each step with declare lower, and finish with SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP) to mark matches with arrows.

How do I measure a candle's upper and lower wick in thinkScript?

On a green candle, the upper wick is high - close and the lower wick is open - low, because the candle closed above where it opened. On a red candle the open and close swap places: the upper wick is high - open and the lower wick is close - low.

What does declare lower do while I build a pattern?

declare lower moves the study into a panel under the price chart. A true/false signal then plots as a line that sits at 0 or jumps to 1, so you can see exactly which candles pass your conditions. Remove declare lower when you are ready to plot arrows on the price chart.

How do I plot an arrow when my candlestick pattern appears?

Make the pattern a plot that returns 1 or 0, then add signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);. ThinkOrSwim paints an up arrow at the lower end of each candle where the value is 1. signal.SetLineWeight(5); makes the arrows bigger and easier to see. The arrow only appears on candles where every condition in the signal is true.

How do I combine several conditions in one thinkScript signal?

Define each condition as its own def variable, then join them with and: plot signal = greenCandle and previousCandleLow and wickCondition;. The signal is 1 only on candles where every condition is true. Adding one condition at a time and applying after each shows you how much each one narrows the results.

Can I change the 4x wick ratio?

Yes. Change the 4 in def wickCondition = lowerWick >= 4 * upperWick;. A smaller number accepts shorter lower wicks and plots more arrows, and a larger number plots fewer. The video uses 4 as an example of a lower wick that is long compared with the upper wick.

Is this candlestick pattern a reliable reversal signal?

Not by itself. In the video, some matches on the Microsoft chart caught the reversal and one met every condition without pinpointing it. The study shows every place the rules triggered, so you can judge each one on the chart. Treat an arrow as a candidate and plan the stop before any trade.

Can I use a custom candlestick pattern in a scan or backtest?

Yes. Once the pattern is one signal variable, the video points out you can use it in an indicator, a scan, an automated trading order or a backtester. Each of those needs the same true/false signal, so the code you wrote and tested on the chart carries over.

## Related tools

[How to Turn Candlestick Patterns into Code: thinkScript tutorial · Free](https://tosindicators.com/thinkscript/how-to-turn-candlestick-patterns-into-code)[Automated trading: Candlestick Example: Automated trading · Free account](https://tosindicators.com/automated-trading/candlestick)[Candle Counter: Indicator · Free](https://tosindicators.com/indicators/candle-counter)[How to Import a thinkScript Study into ThinkOrSwim: thinkScript tutorial · Free](https://tosindicators.com/thinkscript/how-to-import-thinkorswim)[Utility Labels Indicator - Quickly Track Sector Performance and Internals: thinkScript tutorial · Free](https://tosindicators.com/thinkscript/sector-performance)[Automated trading: Entering a Squeeze On a Pullback: thinkScript tutorial · Members](https://tosindicators.com/thinkscript/automated-pullback-squeeze-entry)

## 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.
