3 Weeks Tight - CANSLIM For ThinkOrSwim

8Nick8

Active member
2019 Donor
VIP
The author states:
3 weeks tight is a bullish continuation pattern discovered by IBD's founder, William O'Neil.

The pattern can used as an opportunity to add to an existing position as it often occurs after a breakout above a cup with handle or other technical pattern.

The 3 weeks tight pattern forms when a stock closes within approximately 1% to 1.5% of the prior week's close for at least two weeks. The reason for the bullishness is that it indciates that investors who moved the stock upward in price since the breakout are not taking profits, the price is holding steady.

The buy point is just above the area of resistance formed at the highs of the three weeks plus 10 cents. The ten cent addition to the price is to ensure a push through the resistance at the high of the range.

He9h9w5.png


Find the ToS code in post below.
The Tradingview version: https://www.tradingview.com/script/NHt4hBzv-3-Weeks-Tight-CANSLIM-Technical-Indicator/
 
Last edited by a moderator:
Hi @samer800

May I request your help to convert this script. Thanks

https://www.tradingview.com/script/NHt4hBzv-3-Weeks-Tight-CANSLIM-Technical-Indicator/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Copyright © John Muchow
//@version=4
study("3 Weeks Tight", overlay = true)
//---------------------------------------------------------
// User configurable values and variable initialization
//----------------------------------------------------------
iThreshold = input(title = "% threshold between closes", type = input.float, minval = .5, defval = 1.0, step = .05)
iShowIndicatorLine = input(title = "Horizontal indicator at tight areas?", type = input.bool, defval = true, group = "Visual Indicators")
iIndicatorStyle = input(title = " ‎ ‎ ‎ ‎ ‎Style", type=input.string, options=["Solid", "Dotted", "Dashed", "Arrow Left", "Arrow Right", "Arrow Both"], defval="Solid", group = "Visual Indicators")
iIndicatorLineThickness = input(title = " ‎ ‎ ‎ ‎ ‎Thickness", type = input.integer, minval = 1, maxval = 10, defval = 2, group = "Visual Indicators")
iIndicatorLineColor = input(title = " ‎ ‎ ‎ ‎ ‎Color", type = input.color, defval = #5A98C6, group = "Visual Indicators")
iOffset = input(title = " ‎ ‎ ‎ ‎ ‎Offset up/down", type = input.integer, minval = -5, maxval = 5, defval = 1, step = .1, group = "Visual Indicators")
iShowVerticalBars = input(title = "Vertical band at tight areas?", type = input.bool, defval = true, group = "Visual Indicators")
iShowBuyPrice = input(title = "Show buy price at tight area?", type = input.bool, defval = true, group = "Buy Price")
iBuyPriceOffset = input(title = "Buy price offset up/down", type = input.integer, minval = 0, maxval = 15, defval = 5, step = .5, group = "Buy Price")
iTextSizeOption = input(title = "Text size", type = input.string, options=["Normal", "Large", "Huge"], defval = "Normal", group = "Buy Price")
// Only show content if on a weekly timeframe
onWeeklyChart = timeframe.isweekly
highestHigh = max(high, high[1], high[2])
//---------------------------------------------------------
// Calculate % change between closes
//----------------------------------------------------------
percentChange1 = ((close - close[1]) / close[1]) * 100
percentChange2 = ((close[1] - close[2]) / close[2]) * 100
//---------------------------------------------------------
// 3 weeks tight if closes meet threshold
//----------------------------------------------------------
threeWeeksTight = (abs(percentChange1) <= iThreshold) and (abs(percentChange2) <= iThreshold)
lineStyle = (iIndicatorStyle == "Dotted") ? line.style_dotted :
(iIndicatorStyle == "Dashed") ? line.style_dashed :
(iIndicatorStyle == "Arrow Left") ? line.style_arrow_left :
(iIndicatorStyle == "Arrow Right") ? line.style_arrow_right :
(iIndicatorStyle == "Arrow Both") ? line.style_arrow_both : line.style_solid
//---------------------------------------------------------
// Draw horizontal line above three weeks tight
//----------------------------------------------------------
if (onWeeklyChart and threeWeeksTight and iShowIndicatorLine)
line.new(bar_index[2], high + iOffset, bar_index, high + iOffset, style = lineStyle, width = iIndicatorLineThickness, color = iIndicatorLineColor)
//---------------------------------------------------------
// Show vertical bar indicating tight area?
//----------------------------------------------------------
bgcolor(onWeeklyChart and iShowVerticalBars and threeWeeksTight ? #5A98C6 : na, editable = false)
bgcolor(onWeeklyChart and iShowVerticalBars and threeWeeksTight ? #5A98C6 : na, offset = -1, editable = false)
bgcolor(onWeeklyChart and iShowVerticalBars and threeWeeksTight ? #5A98C6 : na, offset = -2, editable = false)
//---------------------------------------------------------
// Optional alert when 3 weeks tight is detected
//----------------------------------------------------------
alertcondition(threeWeeksTight, title="3 Weeks Tight", message="3 Weeks Tight pattern has been found.")
//---------------------------------------------------------
// Round to specified number of decimal places
//----------------------------------------------------------
fRound(_number, _decimals) =>
power = pow(10, _decimals)
int(_number * power) / power
//---------------------------------------------------------
// Label showing highest high of the tight range
//----------------------------------------------------------
fontSize = (iTextSizeOption == "Normal") ? size.normal :
(iTextSizeOption == "Large") ? size.large : size.huge
var label labelID = label.new(x = na, y = na, textcolor = color.white, color = #15B72C, size = fontSize, tooltip = "Highest high of the tight area + ten cents.")

if (onWeeklyChart and threeWeeksTight and iShowBuyPrice)
// Notice the buy price is $.1 above the highest high,
// the traditional CANSLIM entry to ensure push through resistance
label.set_text(id = labelID, text = "Buy price: \n" + tostring(fRound(highestHigh + .1, 2)))
label.set_x(id = labelID, x = bar_index)
label.set_y(id = labelID, y = high + iBuyPriceOffset)
check below:

CSS:
#// Indicator for TOS
#// Copyright © John Muchow
#study("3 Weeks Tight", overlay = true)
# converted by Sam4Cok@Samer800    - 07/2024 - request from UseThinkScript.com member
input Threshold = 1.0; #(title = "% threshold between closes"
input ShowIndicatorLine = yes ;# = "Horizontal indicator at tight areas?", type = input.bool,
input Offset =  1.0; #  input(title = " ‎ ‎ ‎ ‎ ‎Offset up/down", type = input.integer, minva
input ShowVerticalBars = yes; #(title = "Vertical band at tight areas?",
input ShowBuyPrice = yes; #(title = "Show buy price at tight area?"
input BuyPriceOffset = 5.0; #(title = "Buy price offset up/down", type = input.integer, minval = 0, maxval = 15, defval = 5, step = .5, group = "Buy Price")

def na = Double.NaN;
def last = IsNaN(close);
def cap = getAggregationPeriod();
def errorInAggregation = cap != AggregationPeriod.WEEK;
assert(!errorInAggregation, "Chart Aggregation Period should be Weekly");

#// Only show content if on a weekly timeframe
def onWeeklyChart = yes; # timeframe.isweekly
def highestHigh = highest(high, 3);

#// Calculate % change between closes
def percentChange1 = ((close - close[1]) / close[1]) * 100;
def percentChange2 = ((close[1] - close[2]) / close[2]) * 100;
#// 3 weeks tight if closes meet threshold
def threeWeeksTight = (AbsValue(percentChange1) <= Threshold) and (AbsValue(percentChange2) <= Threshold);

#// Draw horizontal line above three weeks tight
def cond = (onWeeklyChart and threeWeeksTight and ShowIndicatorLine);
def hozLine = if cond then (high + Offset) else 0;

plot value = if cond then RoundUp(highestHigh + 0.1, 2) else na;
plot wt0 = if !last and hozLine then hozLine else na;
wt0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
value.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
value.SetDefaultColor(Color.CYAN);
wt0.SetDefaultColor(Color.GRAY);
#// Show vertical bar indicating tight area?
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

AddCloud(if ShowVerticalBars and (cond or cond[-1] or cond[-2]) then pos else na, neg, Color.GRAY);


AddChartBubble(ShowBuyPrice and cond, low -BuyPriceOffset,"Buy Price:\n" + RoundUp(highestHigh + 0.1, 2), Color.CYAN, no);
#-- END of CODE
 
check below:

CSS:
#// Indicator for TOS
#// Copyright © John Muchow
#study("3 Weeks Tight", overlay = true)
# converted by Sam4Cok@Samer800    - 07/2024 - request from UseThinkScript.com member
input Threshold = 1.0; #(title = "% threshold between closes"
input ShowIndicatorLine = yes ;# = "Horizontal indicator at tight areas?", type = input.bool,
input Offset =  1.0; #  input(title = " ‎ ‎ ‎ ‎ ‎Offset up/down", type = input.integer, minva
input ShowVerticalBars = yes; #(title = "Vertical band at tight areas?",
input ShowBuyPrice = yes; #(title = "Show buy price at tight area?"
input BuyPriceOffset = 5.0; #(title = "Buy price offset up/down", type = input.integer, minval = 0, maxval = 15, defval = 5, step = .5, group = "Buy Price")

def na = Double.NaN;
def last = IsNaN(close);
def cap = getAggregationPeriod();
def errorInAggregation = cap != AggregationPeriod.WEEK;
assert(!errorInAggregation, "Chart Aggregation Period should be Weekly");

#// Only show content if on a weekly timeframe
def onWeeklyChart = yes; # timeframe.isweekly
def highestHigh = highest(high, 3);

#// Calculate % change between closes
def percentChange1 = ((close - close[1]) / close[1]) * 100;
def percentChange2 = ((close[1] - close[2]) / close[2]) * 100;
#// 3 weeks tight if closes meet threshold
def threeWeeksTight = (AbsValue(percentChange1) <= Threshold) and (AbsValue(percentChange2) <= Threshold);

#// Draw horizontal line above three weeks tight
def cond = (onWeeklyChart and threeWeeksTight and ShowIndicatorLine);
def hozLine = if cond then (high + Offset) else 0;

plot value = if cond then RoundUp(highestHigh + 0.1, 2) else na;
plot wt0 = if !last and hozLine then hozLine else na;
wt0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
value.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
value.SetDefaultColor(Color.CYAN);
wt0.SetDefaultColor(Color.GRAY);
#// Show vertical bar indicating tight area?
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

AddCloud(if ShowVerticalBars and (cond or cond[-1] or cond[-2]) then pos else na, neg, Color.GRAY);


AddChartBubble(ShowBuyPrice and cond, low -BuyPriceOffset,"Buy Price:\n" + RoundUp(highestHigh + 0.1, 2), Color.CYAN, no);
#-- END of CODE
Thank you so much!!

@samer800 is it possible to scan out stocks that its vertical cloud was plot in the last 3 weekly bars? Thanks
 
Last edited by a moderator:
Thank you very much for the coding. I have a question. When I paste the code in the custom filter, it showed " Chart Aggregation Period should be Weekly" at the bottom. Even if I changed Aggregation D to W. Can you help. Thanks.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Thread starter Similar threads Forum Replies Date
B-rad Right-half of the Cup & Handle w/ CANSLIM fundamentals SCAN For ThinkOrSwim Custom 3

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
215 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top