Outside Bars and/or Inside Bars (Candle) Combinations For ThinkOrSwim

Thepremier

New member
Can someone help me with a script for an outside day and and an inside day? I would like to create a scan for them.

 
Last edited:
here is a modified version of your study,
..it finds inside bars and outside bars , of 1 and 2 bars.
..inside bars are drawn with cyan , outside bars are drawn with yellow.
..a small arrow is drawn on the big candle. cyan up for inside. yellow down for outside
..it draws lines from the big candle.
..patterns with 2 small bars have a triangle drawn on big candle.

the 2 formulas, insidebar and outsidebar, remove the same, smaller patterns within a larger one.

Code:
# inside_outside_01
# https://usethinkscript.com/threads/inside-outside-bar.12396/
# inside bar and outside bar code,

def na = double.nan;
def price = close;

# inside bar - a big candle and smaller candles after it
def inside1 = high > high[-1] and low < low[-1];
def inside2 = inside1 and high > high[-2] and low < low[-2];

# outside bar - a big candle with smaller candles before it
def outside1 = high > high[1] and low < low[1];
def outside2 = outside1 and high > high[2] and low < low[2];


# remove small insides within larger insides
def insidebar = if inside2[1] then 0 else if inside2 then 2 else if inside1 then 1 else 0;
# remove small outsides within larger outsides
def outsidebar = if outside2[-1] then 0 else if outside2 then 2 else if outside1 then 1 else 0;


input show_small_arrows = yes;
# inside shapes above candles, up wedge
plot zin =  if !show_small_arrows then 0 else insidebar;
zin.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zin.SetDefaultColor(Color.cyan);
zin.setlineweight(2);
zin.hidebubble();


# outside shapes below candles, down wedge
plot zout =  if !show_small_arrows then 0 else outsidebar;
zout.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
zout.SetDefaultColor(Color.yellow);
zout.setlineweight(2);
zout.hidebubble();


plot inside_top =
     if insidebar[0] > 0 then high[0]
else if insidebar[1] > 0 then high[1]
else if insidebar[2] > 1 then high[2]
else na;

plot inside_bot =
     if insidebar[0] > 0 then low[0]
else if insidebar[1] > 0 then low[1]
else if insidebar[2] > 1 then low[2]
else na;

inside_top.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_top.SetDefaultColor(Color.cyan);
inside_top.hidebubble();
inside_bot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_bot.SetDefaultColor(Color.cyan);
inside_bot.hidebubble();


plot outside_top =
     if outsidebar[0] > 0 then high[0]
else if outsidebar[-1] > 0 then high[-1]
else if outsidebar[-2] > 1 then high[-2]
else na;

plot outside_bot =
     if outsidebar[0] > 0 then low[0]
else if outsidebar[-1] > 0 then low[-1]
else if outsidebar[-2] > 1 then low[-2]
else na;

outside_top.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_top.SetDefaultColor(Color.yellow);
outside_top.hidebubble();
outside_bot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_bot.SetDefaultColor(Color.yellow);
outside_bot.hidebubble();


input show_double_shapes = yes;
def vert = 0.006;
#plot y1 = if inside1 then high*1.01 else na;
plot y1 = if show_double_shapes and inside2 then high*(1+vert) else na;
y1.SetPaintingStrategy(PaintingStrategy.triangles);
y1.SetDefaultColor(Color.cyan);
y1.setlineweight(4);
y1.hidebubble();

#plot y2 = if inside2 then high*1.02 else na;
plot y2 = if show_double_shapes and outside2 then low*(1-vert) else na;
y2.SetPaintingStrategy(PaintingStrategy.triangles);
y2.SetDefaultColor(Color.yellow);
y2.setlineweight(4);
y2.hidebubble();
#

nN6oH34.jpg
Great scrip!!!! Is there a way to make a chart alert? for this?
 
I am using the above logic but I am seeing some inconsistencies - It seems it does not highlight all the candles that are inside -

#########################
# Inside and Outside Bar
# Mobius
# 8.7.2017

def inside = high < high[1] and low > low[1];
def outside = high > high[1] or low < low[1];
AssignPriceColor(if inside
then color.yellow
else if outside
then color.GRAY
else color.current);
#
########################https://ibb.co/bztrRWb

https://ibb.co/bztrRWb

I understand the logic ..........I have tried chart bubble also and bubble works. But the color of the candle is off
 
Last edited by a moderator:
I am using the above logic but I am seeing some inconsistencies - It seems it does not highlight all the candles that are inside -

#########################
# Inside and Outside Bar
# Mobius
# 8.7.2017

def inside = high < high[1] and low > low[1];
def outside = high > high[1] or low < low[1];
AssignPriceColor(if inside
then color.yellow
else if outside
then color.GRAY
else color.current);
#
########################https://ibb.co/bztrRWb

https://ibb.co/bztrRWb

I understand the logic ..........I have tried chart bubble also and bubble works. But the color of the candle is off
The yellow candle is defined according to the script that you included in your post.
The chart bubble is obviously using a definition in a script that you didn't share.

Modify the inside bar definition of the script coloring your candle to match the inside bar definition in your chart bubble.
 
I am using the above logic but I am seeing some inconsistencies - It seems it does not highlight all the candles that are inside -

#########################
# Inside and Outside Bar
# Mobius
# 8.7.2017

def inside = high < high[1] and low > low[1];
def outside = high > high[1] or low < low[1];
AssignPriceColor(if inside
then color.yellow
else if outside
then color.GRAY
else color.current);
#
########################https://ibb.co/bztrRWb

https://ibb.co/bztrRWb

I understand the logic ..........I have tried chart bubble also and bubble works. But the color of the candle is off

Why do you say 'the logic above', and then list code 'below' your words? Are you referencing an entirely different code somewhere? If so, mention the post number. (there are 82 posts before yours, so it's hard to to tell which 'post above' you are referring to).
if you click on a post number, the web link is updated to point to that post. then copy/paste the link when you make a post of your own.

can you list A stock and chart time of where you see these differences?
What exactly are you looking for that you are not seeing?
the formula for a one bar inside pattern looks right, so it should be working..

I was going to say, the outside formula is wrong, but it's just a different way of doing it. Below is a link to what I have seen, A large bar that is larger than the previous bar.


inside bar
large bar, then smaller one
https://priceaction.com/price-actio...e bar” pattern is,than the previous bar's low.


outside bar
small bar, then larger one
https://www.newtraderu.com/2021/10/29/outside-bar-candlestick-pattern/
 
Last edited:
Thanks for your reply......Let's try again.

1. I used the code from post #2
https://usethinkscript.com/threads/...e-combinations-for-thinkorswim.8336/post-1397

2. I looked up CCL on 5 Min chart
https://ibb.co/4WYKcc6

3. The code logic is - if it is an inside bar color should be cyan. That is what I understand but I am seeing "4" inside bars that are green.

Now, I am aware of the fact the last line "else color.current" was the cause of my confusion. In the case of 4 inside bars that were painted green high or low were equal to the previous bar thus the last line of the code was executed.

Now the question is, what do you call a bar when its high or low is equal to the high or low of the previous bar?
 
Inside Outside bar!

def insideBar = high < high[1] and low > low[1];
def outsideBar = high > high[1] and low < low[1];

plot barType = if insideBar then 1 else if outsideBar then 1 else 1;
barType.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
barType.AssignValueColor(if outsideBar then Color.orange else Color.black);

AssignPriceColor(if insideBar then Color.blue else if outsideBar then color.DARK_ORANGE else Color.CURRENT);
 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
257 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