Candle Counter

Easily analyze your favorite markets to find how many green vs. red candles in a row they tend to have, before seeing a reversal.

16 mins
Beginner-Friendly
youtube-video-thumbnail
Table of Contents
    Add a header to begin generating the table of contents
    Table of Contents
      Add a header to begin generating the table of contents

      Candle Counter Introduction

      Understanding market momentum and trend exhaustion plays a crucial role in successful trading.

      The Candle Counter Indicator provides insight into consecutive green or red candles, making it easier for you to analyze trends, spot potential reversals, and gauge market conditions effectively.

      In this tutorial, we’ll build a Candle Counter Indicator using thinkScript in ThinkOrSwim.

      By the end, you’ll understand how to create counter variables, reset them based on conditions, plot histogram values, and utilize this indicator in your trading strategies.

      Volatility Box Invite

      We are TOS Indicators.com, home of the Volatility Box.

      The Volatility Box is our secret tool, to help us consistently profit from the market place. We’re a small team, and we spend hours every day, after the market close, doing nothing but studying thousands of data points to keep improving and perfecting the Volatility Box price ranges.

      We have two different Volatility Boxes - a Futures Volatility Box and a Stock Volatility Box.

      Futures Volatility Box - Trade Major Markets With an Edge

      Designed For: Futures, Micro-Futures and Index Market Traders
      Supported Models: Hourly Volatility Box models
      Supported Markets: 10 Major Futures Markets

      The Futures Volatility Box comes with:

      • 5 Volatility Models for each market
      • Support for 10 Futures Markets (/ES, /NQ, /YM, /RTY, /CL, /GC, /SI, /ZB, /HG, /NG)
      • Video Setup Guide
      • Trade Plan
      • Access to all members-only resources, including Squeeze Course

      Learn More About the Futures Volatility Box

      Trade futures and micro futures with a consistent volatility edge

      Stock Volatility Box - Powerful Web Based Volatility Platform

      Designed For: Stock and Options Traders
      Supported Models: Hourly and Daily Volatility Box models
      Supported Markets: 10,000+ Stocks and ETFs (new markets added frequently)

      A Stock Volatility Box membership includes access to: 

      • Live Scanner - A powerful scanner we've built from scratch, to scan 10,000 symbols every 2 seconds for new volatility breaches
      • Dashboard - A quick and easy way to view daily volatility model levels online
      • Short Interest Scanner - Short interest, Squeeze, and EMA data to find short squeezes
      • Squeeze Course - All of our proprietary squeeze tools, including robust backtesters
      • All Members Only Indicators - We don't nickel and dime you. Everything really is included.
      • And much more!

      Learn More About the Stock Volatility Box

      Trade stocks and options with a consistent volatility edge

      What is the Candle Counter Indicator?

      The Candle Counter Indicator tracks consecutive green or red candles in a specified timeframe. For instance, in the S&P 500, this indicator can reveal patterns like the average number of consecutive up or down days, maximum streaks of green or red candles, and give a general sense of trend strength and potential exhaustion points. The goal is to understand the behavior of trends over time and assess whether a trend is likely to continue or reverse based on historical patterns.

      How to Use the Candle Counter Indicator

      The Candle Counter Indicator helps with:

      • Spotting Trend Strength and Exhaustion: By counting the consecutive number of green or red candles, you can gauge how strong a trend might be or if it’s nearing exhaustion.
      • Identifying Trend Reversals: Prolonged streaks of green or red candles can signal upcoming reversals.
      • Quantifying Trends: By knowing the average number of consecutive green or red candles, you can better assess market behavior for specific securities.

      For instance, if you consistently observe five green candles in a row before a red candle appears, a streak of six or more green candles might suggest an overextended move, signaling a possible upcoming reversal.

      Building the Candle Counter Indicator in thinkScript

      Step 1: Getting Started

      To start coding in ThinkOrSwim:

      1. Click on the Studies icon and select Create.
      2. Give your script a name, like Candle Counter, and delete any pre-existing code.

      Step 2: Define Green and Red Candles

      First, define green and red candles based on the closing and opening prices:

      def greenCandle = close > open;
      def redCandle = close < open;
      • Green candles are defined by a close higher than the open.
      • Red candles are the opposite, with a close lower than the open.

      Step 3: Initialize Counter Variables

      Create counters to track consecutive green and red candles. These counters will reset when the opposite color candle appears:

      def greenCounter = if greenCandle then greenCounter[1] + 1 else 0;
      def redCounter = if redCandle then redCounter[1] + 1 else 0;
      • greenCounter increases by 1 for every green candle, resetting to 0 when a red candle appears.
      • Similarly, redCounter tracks consecutive red candles, resetting when a green candle occurs.

      Step 4: Calculate Maximum and Average Values

      To gain additional insight, let’s calculate the maximum number of consecutive green and red candles as well as the average:

      # Calculate maximum green and red streaks
      def maxGreenCount = HighestAll(greenCounter);
      def maxRedCount = HighestAll(redCounter);
      
      # Calculate the total and average streak lengths
      def totalGreenSum = TotalSum(greenCounter);
      def totalRedSum = TotalSum(redCounter);
      
      def greenStreaks = TotalSum(if greenCounter > 0 then 1 else 0);
      def redStreaks = TotalSum(if redCounter > 0 then 1 else 0);
      
      def avgGreenCount = totalGreenSum / greenStreaks;
      def avgRedCount = totalRedSum / redStreaks;

      Step 5: Plot Histogram and Label Values

      Next, plot these values as histograms for easy visualization:

      declare lower;
      
      plot GreenHistogram = greenCounter;
      GreenHistogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
      GreenHistogram.SetDefaultColor(Color.GREEN);
      
      plot RedHistogram = redCounter;
      RedHistogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
      RedHistogram.SetDefaultColor(Color.RED);

      Finally, add labels to display the maximum and average values:

      AddLabel(yes, "Max Green Streak: " + maxGreenCount, Color.GREEN);
      AddLabel(yes, "Max Red Streak: " + maxRedCount, Color.RED);
      AddLabel(yes, "Avg Green Streak: " + Round(avgGreenCount, 1), Color.GREEN);
      AddLabel(yes, "Avg Red Streak: " + Round(avgRedCount, 1), Color.RED);

      Applying the Candle Counter Indicator

      Once your indicator is up and running, apply it to different securities to observe unique patterns:

      1. Market Indices: Apply the Candle Counter to indices like the S&P 500, Dow Jones, or Nasdaq to compare trend behaviors.
      2. Stocks: Use this on individual stocks to identify unique behavior patterns in different companies.
      3. Timeframes: Experiment with different timeframes to gauge trend strength across intraday, daily, or weekly charts.

      Conclusion

      With the Candle Counter Indicator, you gain a practical tool to analyze market trends. By counting consecutive green or red candles, you can better anticipate trend exhaustion and potential reversals. This indicator not only enhances your trend-following strategy but also helps you refine your entries and exits based on historical candle patterns.

      Try it out and integrate this tool into your trading strategies!

      downloads

      Download the Candle Counter Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Download Indicator

      Download the Candle Counter Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Have your own idea?

      Let us help you turn your trading strategy into a powerful indicator, scan and backtester.