Cup and Handle Indicator for ThinkorSwim

mo2020

New member
If you search for the most popular charting patterns, you will find that the cup and handle pattern is right at the top of the list.

According to Investor’s Business Daily, the cup and handle pattern is “the starting point for scoring runs and winning the investing game.” And yet, despite the popularity of this indicator, none of the major charting platforms offer a method of automatically identifying and charting the cup and handle pattern—and forget about searching for them. That travesty ends today! My cup and handle indicator and scanner is available now, and exclusively, on the Thinkorswim platform.

Works with any instrument and on any time frame

Works with Thinkorswim Mobile

Includes scanner to find cup and handle patterns
 
Last edited by a moderator:
Solution
Look up this built in Study: SemiCupFormation in the ThinkorSwim online Study Guide. It's from TASC magazine. (y) It will get you to the bottom of a cup where you can then look for a pocket pivot.

Ben is correct in saying that it cannot be done in thinkscript. A cup with handle is very subjective. It has to be found by looking and recognizing them on your list of charts.
  • Follow any of the former IBD managers on twitter then go to their websites and you will find that these big dollar individuals don't have that type of study either.
  • Feel free to throw $250 down a rat hole and then pay someone to translate it.
  • I have heard someone came up with something close by using a Neural Network and years of machine...

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

Shinthus

Member
2019 Donor
My intention is really not to be a wet blanket but I just checked out this link and the examples of CWHs on there are not consistent with everything I have ever learned about them reading books and articles. They especially do not match up with Bill O'Neil's (Investor Business Daily founder) interpretation. The handle that forms on the right side of the cup, as I understand it, needs to show a moderate price decline. The psychology behind this is that the poor fools who got in at the highs of the left cup rim almost always follow human nature and sell as soon as they break even when the handle begins forming at the same price level on the right. Does this all make sense?
 

Adeel06

New member
According to Investor’s Business Daily, the cup and handle pattern is “the starting point for scoring runs and winning the investing game.” And yet, despite the popularity of this indicator, none of the major charting platforms offer a method of automatically identifying and charting the cup and handle pattern—and forget about searching for them.

That travesty ends today! My cup and handle indicator and scanner is available now, and exclusively, on the Thinkorswim platform.

This was posted on researchtrade, it costs $250, was wondering if there’s a way to code this for our members? :)
 

markos

Well-known member
VIP
Look up this built in Study: SemiCupFormation in the ThinkorSwim online Study Guide. It's from TASC magazine. (y) It will get you to the bottom of a cup where you can then look for a pocket pivot.

Ben is correct in saying that it cannot be done in thinkscript. A cup with handle is very subjective. It has to be found by looking and recognizing them on your list of charts.
  • Follow any of the former IBD managers on twitter then go to their websites and you will find that these big dollar individuals don't have that type of study either.
  • Feel free to throw $250 down a rat hole and then pay someone to translate it.
  • I have heard someone came up with something close by using a Neural Network and years of machine learning. They still had to go through all of the charts that the computer program spit out.
  • I have been an IBD investor since the early 1990s and currently belong to an IBD meet up group. Nobody in any meet up groups has such a thing, at least, if they do, they're not telling anyone.
Sorry for the tough love, Markos

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#

script VariableMax {
    input price = close;
    input min = 0;
    input max = 0;
    input maxOffset = 0;
    plot VMax = fold i = min to max with m = Double.NEGATIVE_INFINITY do Max(m, getValue(price, i, maxOffset));
}

script VariableMin {
    input price = close;
    input min = 0;
    input max = 0;
    input maxOffset = 0;
    plot VMin = fold i = min to max with m = Double.POSITIVE_INFINITY do Min(m, getValue(price, i, maxOffset));
}

script DX {
    input DXPlus = close;
    input DXMinus = close;
    input min = 0;
    input max = 0;
    input maxOffset = 0;

    def SumDXPlus = fold i = min to max with p do p + getValue(DXPlus, i, maxOffset);
    def SumDXMinus = fold j = min to max with m do m + getValue(DXMinus, j, maxOffset);
    plot DX = AbsValue(SumDXPlus - SumDXMinus) / (SumDXPlus + SumDXMinus + 0.000000001) * 100;
}

input price = close;
input minLength = 20;
input maxLength = 252;
input factor = 2.0;

assert(minLength > 0, "'min length' must be positive: " + minLength);
assert(factor >= 1, "'factor' must be greater than or equal to 1: " + factor);

def rawOffset = fold i = minLength to maxLength with off = -1 do if off == -1 and getValue(price, i, maxLength) > price * factor then i else off;
def offset = if IsNaN(rawOffset) then -1 else rawOffset;

def logPrice = log(price);

def B2Offset = if offset < 0 then -1 else round(offset * 0.6, 0);

def DXPlus = Max(logPrice - logPrice[1], 0);
def DXMinus = Max(logPrice[1] - logPrice, 0);
def DX1 = DX(DXPlus, DXMinus, B2Offset + 1, offset + 1, maxLength);
def DX2 = DX(DXPlus, DXMinus, 0, B2Offset + 1, maxLength);

def B3Offset = if offset < 0 then -1 else round(offset * 0.4, 0);
def highestB2toB3 = VariableMax(logPrice, B3Offset + 1, B2Offset + 1, maxLength);
def highestB3toB5 = VariableMax(logPrice, 0, B3Offset + 1, maxLength);

def hiLogPrice = if IsNaN(getValue(logPrice, offset, maxLength)) then logPrice else getValue(logPrice, offset, maxLength);
def loLogPrice = VariableMin(logPrice, 0, offset + 1, maxLength);
def L2 = loLogPrice * 0.6 + hiLogPrice * 0.4;
def L3 = loLogPrice * 0.4 + hiLogPrice * 0.6;

plot SemiCup = offset > 0 and DX1 > 25 and DX2 < 25 and highestB2toB3 < L3 and highestB3toB5 < L2;

# find last cup
def curBar = barNumber();
def cupEnd = HighestAll(if SemiCup then curBar else Double.NaN);

def rawCupOffset = HighestAll(if cupEnd == curBar and SemiCup then offset else Double.NaN);
def cupOffset = if IsNaN(rawCupOffset) then 0 else rawCupOffset;

def cupHiLogPrice = HighestAll(if curBar == cupEnd then getValue(logPrice, cupOffset, maxLength) else Double.NaN);
def cupLowLogPrice = HighestAll(if curBar == cupEnd then VariableMin(logPrice, 0, cupOffset + 1, maxLength) else Double.NaN);

def found = curBar >= cupEnd - cupOffset and curBar <= cupEnd;

# cup visualization
def hi = exp(cupHiLogPrice);
def lo = exp(cupLowLogPrice);
def t = curBar - cupEnd;
def dev = (hi - lo) * Power(t / cupOffset, 10);
plot Curve = if found then Min(hi, dev + 0.98 * lo) else Double.NaN;

AddLabel(cupOffset, "Semi-Cup formation size: " + (cupOffset + 1));
SemiCup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
SemiCup.SetLineWeight(3);
SemiCup.SetLineWeight(3);
Curve.SetDefaultColor(GetColor(2));
 
Solution

RDMercer

Member
Have you ever been able to run the SemiCupFormation study? Are you able to get this to run in TOS now? I cannot. Nor can TDA / TOS Trading Desk who is top level support. I sent an email request to Thinkorswim in Utah to review / fix but no reply as yet. Wondering if there are some user settings overlooked or reason besides a coding flaw. If you have this study working would you please share the user settings so I might replicate? Many Thanks! RDM
 
Last edited:

korygill

Active member
VIP
So who has thoughts on possible Cup and Handle on CRM?

See also: http://www.newtraderu.com/2012/08/20/why-the-cup-handle-chart-pattern-works/

wAaZiM3.png


Any pattern can be traded, especially horizontal ones where essentially it's a line in the sand with defined risk/reward. You can almost pick any point in time and do the same. Just a matter of probabilities. Same can be said for ORB, ranging markets, etc...for horizontal strategies. It's a lot harder on diagonals (diagonal H&S vs a clean horizontal one)...Schabacker covers this in his books and others.
 

Yprez

New member
I see that two its subjective but that's why you have to play your signal and strat with determined risk/reward. its a long game but strat should be consistent and back tested im really liking and back test the reversal indicator signal strategy having great success looking to take it live soon myself but its all about discipline and rules stick with your edge consistency is key its a game of percentages overall. I would take it on neck break with break as SL maybe little below it but its all subjective to account size and tolorence.
 

RDMercer

Member
@korygill Thanks! I get the same error. Ditto others at TOS trade desk. If / When I get a reply to my fix request in a few days I'll post it. Stay tuned.

@markos The IBD stuff is totally automated. Has been for many years but they ain't selling it for any amount because it's their lifeblood. How do I know? 'Cause I asked Bill O'Neil once after I heard him give a class in the late '80's. There's no way they sit around looking at 1,000's of charts though they do use industry groups / composite rankings to winnow some of the chaff. As stated TOS is limited 'cause of the scripting language but if TDA was really interested the solution could be hard coded into the TOS product. There are sites selling C&H pattern charts / watchlists. O'Neil & Co. used to sell Daily Graphs weekly / monthly paper books filled with charts many of which were C&H. Last I checked IBD still sell a proprietary chart service which is prolly what former IBD money managers utilize.
 

Zachc

Member
2019 Donor
What your asking for simply breaks down like this.

Look up into the sky and tell me what the cloud looks like. You say it looks like a dog.
Now I look up at the same cloud and my brain focuses on finding a dog in the cloud and I see it.
Now take a picture of that cloud and upload it to your computer and write a program to find a dog.

When you ask a computer to interpereate what you are seeing it needs a finite set of rules that can define all the characteristics of the specific object you are seeing. If that object is static great we can test that but no two cup and handle formations are exactly alike.

Donate your time and money to charity it will be a better investment.
 

RDMercer

Member
@Zachc Apparently William O'Neil and Co. long ago solved whatever deep dark mystery exists to automate a C&H scanner. It isn't impossible to do... just requires data, an algorithm, and enough computing horsepower / coding to accomplish the task. We did, after all, send men to the moon? The issue is TOS scripting isn't robust enough nor is the platform strong enough. Went down this rabbit hole with TOS developer long before TDA bought it out and concluded it was easier to just buy an IBD subscription and export/import a ticker list into TOS. Let O'Neil do the heavy lifting and you get industry strength / composite ratings as a bonus. Not impossible.

Here's a link to another platform's C&H scan: https://swingtradebot.com/events/61-cup-with-handle/equities
Here's a C&H subscription site: https://www.breakoutwatch.com/index.php
 
Last edited:

Zachc

Member
2019 Donor
@RDMercer I am speaking from a purely quantitative point of view when I say that describing chart patterns is equivalent to naming clouds.

One idea might be to aggregate all the cup and handle subscriptions and pick a random signal from each. Then randomly choose the same number of stocks that were not showing a C&H signal and track the progress of both portfolios. Track both portfolios for a time and report on their performance relative to each other.

How close to random chance is the C&H signal, does it provide a statistical edge? Trust by verify everyone.
 

horserider

Well-known member
VIP
From Bulkowski site.

Cup with Handle: Important Bull Market Results
  • Overall performance rank (1 is best): 6 out of 56
  • Break even failure rate: 5%
  • Average rise: 52%
  • Throwback rate: 62%
  • Percentage meeting price target: 62%
  • The above numbers are based on 912 perfect trades.
 

RDMercer

Member
@korygill @markos @BenTen @Zachc @horserider

On 9/10 I reached out by email to ThinkOrSwim support in Utah re the TOS study "SemiCupFormation" not working as either a study or a scan. Here is their 9/18 reply:

"Thank you for reaching out to the Thinkscript team. I am sorry that you are having issues with the SemiCupFormation Study. A few of us have taken a look at the study and we are getting the same results that you have gotten. In short, this is because the study is too complex to run as a scan. This is due to a few of the functions used in the hard coding of the study; namely the Recursive function and ‘fold’ statements. Therefore, using this study in the scan tab will continue to yield an error message or no results. I am sorry for any inconvenience that this may cause. If there is anything else we can do to help, please let us know."

Given that TOS failed to fully address my original inquiry I immediately replied with the following:

"Ok. Won’t function as a scan. SOOOOO…. Did anyone think to test the study as just a study in a chart? It doesn’t function that way either. Need a fix soonest, please."

Today is 9/23. I will go to TDA management if I've not received an acceptable reply by Thrs 9/26. Will post all outcomes as I receive them. Meantime, if anyone has been able to get this study to actually work, even in the past, I would appreciate a heads-up. Stay tuned!
 

RobertPayne

Member
Hello. I am the author of the cup and handle indicator for Thinkorswim that you have been discussing.

BenTen said:
Not possible to create an indicator for this in my opinion. You would have to identify and draw them yourself.

It is possible to automate the identification of, at least, some cup and handle patterns in Thinkorswim. This indicator, obviously, will not identify every possible cup and handle pattern, but it will, certainly, make the process of finding some of them much easier.

Shinthus said:
I just checked out this link and the examples of CWHs on there are not consistent with everything I have ever learned about them reading books and articles. They especially do not match up with Bill O'Neil's (Investor Business Daily founder) interpretation. The handle that forms on the right side of the cup, as I understand it, needs to show a moderate price decline.

The patterns identified by my indicator do have a handle that show a moderate price decline. I chose not to draw the handle as declining because I wanted the breakout line to be obvious. However, if you look at the candles themselves, it is obvious that they do "show a moderate price decline".

mituoPA.png


RDMercer said:
On 9/10 I reached out by email to ThinkOrSwim support in Utah re the TOS study "SemiCupFormation" not working as either a study or a scan. Here is their 9/18 reply:

"Thank you for reaching out to the Thinkscript team. I am sorry that you are having issues with the SemiCupFormation Study. A few of us have taken a look at the study and we are getting the same results that you have gotten. In short, this is because the study is too complex to run as a scan.

While the SemiCupFormation may not work as either a study or a scan, my indicator does. For instance, here is a scan of the daily S&P500 that I ran just a moment ago. You will notice in the HBAN example that the handle isn't drooping a great deal, but it is showing a moderate decline.

HZxHoCM.png


XXTqJVX.png


One last example. This ended up being a failed pattern, but the scan and indicator did both pick up on the pattern.

naoQ0iZ.png
 
Last edited:

Volatility Trading Range

VTR is a momentum indicator that shows if a stock is overbought or oversold based on its Weekly and Monthly average volatility trading range.

Download the indicator

Similar threads

Top