Spinning Tops Candlestick Pattern for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Spinning top is a candlestick pattern that shows indecision in the market.

It’s a small candlestick pattern. In this pattern, the stock prices open and close are near each other. This pattern forms when there’s indecision among the buyers and sellers in the uptrend, downtrend, or sideways trend. The pattern suggests a possible change in trend.

0L79ppt.png

czmI3SQ.png


thinkScript Code

Code:
# Spinning Top Candlestick Pattern
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/LyNzdJVX-Spinning-Tops/

input stsize = 0.5;
def spinningtop = (open>close) and ((high-low)>(3*(open-close))and(((high-open)/(.001+high-low))< stsize)and (((close-low)/(.001+high-low))< stsize)) or (close>open) and ((high-low)>(3*(close-open))and(((high-close)/(.001+high-low))< stsize)and (((open-low)/(.001+high-low))< stsize));

assignPriceColor(if spinningtop then Color.CYAN else Color.WHITE);

A few resources to help you learn more about this pattern:
 

Playstation

Active member
VIP
Hi I'm new! This seems to work very well on oil futures, 5mins. Due to me being partial colour blind, I can't spot colours that well, hence using a white background, with black and hollow candles. Is it possible to change the code "then Color.BLUE else Color.[no change]);
I'm unsure how to change this variable.

Edit: silly me. all i have to do is change color to black, since the up candles are hollow
 
Last edited:

BenTen

Administrative
Staff member
Staff
VIP
@Playstation Here you go:

Code:
# Plot Signal
plot signal = spinningtop;
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal.SetDefaultColor(Color.CYAN);
signal.SetLineWeight(1);

The arrow isn't to give you direction, it's just telling you where the spinning top is.
 

MHCain

New member
@BenTen I saw an indicator on TView where the “body” of the Spinning Top candle is displayed a S/R line. I can probably cut and paste a code but cannot find a code that does that. I’ve only found S/R lines that display High/Low/Middle. Thanks for the guidance.
 

BenTen

Administrative
Staff member
Staff
VIP
@MHCain Take a look at the "fancy version" of the Blast Off indicator here and use part of its script for this one.
 

Moops

New member
I usually refactor the code to get a better understanding of what it's doing. Here's what I got from this:

Code:
def body_top = Max(open, close);
def body_bottom = Min(open, close);
def upper_shadow = high - body_top;
def lower_shadow = body_bottom - low;
def candle_height = high - low;

def body_height_is_less_than_one_third_candle_height = candle_height > 3 * BodyHeight();
def upper_shadow_height_is_less_than_one_half_ish_candle_height = upper_shadow < (.001 + candle_height) / 2;
def lower_shadow_height_is_less_than_one_half_ish_candle_height = lower_shadow < (.001 + candle_height) / 2;

plot spinning_top = body_height_is_less_than_one_third_candle_height
    and upper_shadow_height_is_less_than_one_half_ish_candle_height
    and lower_shadow_height_is_less_than_one_half_ish_candle_height;

assignPriceColor(if spinning_top then Color.RED else Color.WHITE);


It appears to find some spinning tops, but according to Steve Nison, linking whether it is a spinning top to the heights of the shadows like this is going to leave a lot of stuff out. Make your decisions on what sources you trust and understand that not every source agrees.
“The Japanese term for a small real body (black or white) is a spinning top. Exhibit 3.6 shows examples of spinning tops. The lines illustrated in Exhibit 3.6 have upper and lower shadows, but the sizes of the shadows are not important. It is the small size of the real body that makes these spinning tops.”

Excerpt From: Steve Nison. “Japanese Candlestick Charting Techniques.” Apple Books. https://books.apple.com/us/book/japanese-candlestick-charting-techniques/id648523437
 

Moops

New member
Here's an alternative, attempting to just go by body size, relative to the average body size of the past 20 bars, adjustable of course. This is assuming that relatively small is when you start approaching a standard deviation less than the average. I use .5 standard deviation as a starting point since it still seems to be fairly small.

Code:
input scaling_factor= 0.5;
input length = 20;

def average_body_height = Average(BodyHeight(),length);
def body_height_std_dev = StDev(BodyHeight(),length);
def small_body = BodyHeight() < average_body_height - scaling_factor *  body_height_std_dev;

plot spinning_top = small_body;

assignPriceColor(if spinning_top then Color.RED else Color.WHITE);
 
Top