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:
Hi,

I am a newbie to TOS. I appreciate your advice to write a script that contains (1) Inside and Outside Bar (2) HolyGrail indicator? Thank very much.

This is the Outside Bar Script I found and how do we write a script for Inside Bar using this format?

plot Bullish = high > high[1] and
low < low[1] and
close > open;
Bullish.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Up);
Bullish.SetDefaultColor(Color.Green);
Bullish.setLineWeight(3);

plot Bearish = high > high[1] and
low < low[1] and
close < open;
Bearish.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Down);
Bearish.SetDefaultColor(Color.Red);
Bearish.setLineWeight(3);
 
I can't seem to get this working: Can someone take a look and see what's wrong here? Thanks I have no coding skills. This was posted on Twitter and said to work on TOS, but not for me.

// TW - Holy Grail
// highlights holy grail pattern

study(title="TW - Holy Grail", shorttitle="TW - Holy Grail", overlay=true)


outBar = low[1] < low[2] and high[1] > high[2]
inBar = low > low[1] and high < high[1]

holyGrail = inBar and outBar == 1

barcolor (holyGrail ==1 ? yellow : na)
barcolor (holyGrail ==1 ? yellow : na, offset = -1)

i just made this upper chart study for someone. will post it today
ref this
https://www.tradingview.com/script/uYiilgYb-TW-Golden-Indicators/

Ruby:
# golden_01b

# https://www.tradingview.com/script/uYiilgYb-TW-Golden-Indicators/
# convert tradingview study
#// TW Golden Indicators Package
#// This package features BB (with 20 ma), inside bar color change (white), outside bar color change (black), and holy grail 2-candle pattern background higlhlight (yellow)

def lastbar = !isnan(close[0]) and isnan(close[-1]);
def src = close;
input length = 20;
input mult = 2.0;
def mult2 = if mult > 50 then 50 else if mult < 0.001 then 0.001 else mult;

# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
#  EXPONENTIAL, HULL, SIMPLE, WEIGHTED, WILDERS
input avg1_type =  AverageType.simple;
def basis = MovingAverage(avg1_type, src, length);
def dev = mult2 * StDev( src , length );
def upper = basis + dev;
def lower = basis - dev;

# horz lines
plot basisLine = highestAll(if isNaN(close[-1]) then basis else Double.NaN);
basisline.SetDefaultColor(Color.red);
basisline.SetStyle(Curve.SHORT_DASH);
plot upperLine = highestAll(if isNaN(close[-1]) then upper else Double.NaN);
upperline.SetDefaultColor(Color.magenta);
plot lowerLine = highestAll(if isNaN(close[-1]) then lower else Double.NaN);
lowerline.SetDefaultColor(Color.magenta);

# inside and outside bars
def inBar = low > low[1] and high < high[1];
def outBar = low < low[1] and high > high[1];
def holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];

input bubble_ht_offset = 0.0006;
addchartbubble(inbar, (high * (1 + bubble_ht_offset)), "IB", color.yellow, yes);
addchartbubble(outbar, (low * (1 - bubble_ht_offset)), "OB", color.blue, no);

def off = 1;
addchartbubble(lastbar[off] and holyGrail[off] and inbar[off], close, "Holy Grail" + "\nInbar", color.yellow, yes);
addchartbubble(lastbar[off] and holyGrail[off] and outbar[off], close, "Holy Grail" + "\nOutbar", color.yellow, yes);

plot hg2 = holygrail;
hg2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_up);
hg2.SetDefaultColor(Color.white);
hg2.setlineweight(3);
#
 
Last edited:
i just made this upper chart study for someone. will post it today
ref this
https://www.tradingview.com/script/uYiilgYb-TW-Golden-Indicators/

Ruby:
# golden_01b

# https://www.tradingview.com/script/uYiilgYb-TW-Golden-Indicators/
# convert tradingview study
#// TW Golden Indicators Package
#// This package features BB (with 20 ma), inside bar color change (white), outside bar color change (black), and holy grail 2-candle pattern background higlhlight (yellow)

def lastbar = !isnan(close[0]) and isnan(close[-1]);
def src = close;
input length = 20;
input mult = 2.0;
def mult2 = if mult > 50 then 50 else if mult < 0.001 then 0.001 else mult;

# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
#  EXPONENTIAL, HULL, SIMPLE, WEIGHTED, WILDERS
input avg1_type =  AverageType.simple;
def basis = MovingAverage(avg1_type, src, length);
def dev = mult2 * StDev( src , length );
def upper = basis + dev;
def lower = basis - dev;

# horz lines
plot basisLine = highestAll(if isNaN(close[-1]) then basis else Double.NaN);
basisline.SetDefaultColor(Color.red);
basisline.SetStyle(Curve.SHORT_DASH);
plot upperLine = highestAll(if isNaN(close[-1]) then upper else Double.NaN);
upperline.SetDefaultColor(Color.magenta);
plot lowerLine = highestAll(if isNaN(close[-1]) then lower else Double.NaN);
lowerline.SetDefaultColor(Color.magenta);

# inside and outside bars
def inBar = low > low[1] and high < high[1];
def outBar = low < low[1] and high > high[1];
def holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];

input bubble_ht_offset = 0.0006;
addchartbubble(inbar, (high * (1 + bubble_ht_offset)), "IB", color.yellow, yes);
addchartbubble(outbar, (low * (1 - bubble_ht_offset)), "OB", color.blue, no);

def off = 1;
addchartbubble(lastbar[off] and holyGrail[off] and inbar[off], close, "Holy Grail" + "\nInbar", color.yellow, yes);
addchartbubble(lastbar[off] and holyGrail[off] and outbar[off], close, "Holy Grail" + "\nOutbar", color.yellow, yes);

plot hg2 = holygrail;
hg2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_up);
hg2.SetDefaultColor(Color.white);
hg2.setlineweight(3);
#
this is incredible, thanks so much for porting this over to ToS.

is there anyway to recolor the IB/OB candle itself as well?
 
Hi. I'm trying to modify this script to show inside bar with green arrow if volume bar is green and red arrow if volume bar is red, Also would like to add a condition that if the candle is a hammer then it will show with different color. That's a code that was provided by someone on this forum. Thanks in advance

def lo = low;
def hi = high;
def vo = volume;

def s = if (hi[1] >= hi[0] and lo[1] < lo[0]) then 1 else 0;
plot did = s;
did.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
did.SetLineWeight(3);
did.AssignValueColor(Color.LIME);
 
"Hammer candle script"
input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input shadowFactor = 2.0;

assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
assert(shadowFactor >= 0, "'shadow factor' must not be negative: " + shadowFactor);

def BodyHeight = BodyHeight();
def AverageBodyHeight = Average(BodyHeight, length);
def ErrMargin = 0.05 * AverageBodyHeight;
def IsShort = BodyHeight < bodyFactor * AverageBodyHeight;

plot Bullish = IsDescending(close, trendSetup) and
IsShort and
high - Max(open, close) <= ErrMargin and
Min(open, close) - low > shadowFactor * BodyHeight;

Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(4));
Bullish.SetLineWeight(2);

--------------------------------------------------------------------------------------------------------------
Updated script ( need help)

def lo = low;
def hi = high;
def vo = volume;

def l = If (hi[1] >= hi[0] and lo[1] < lo[0]);
def s = If (hi[1] <= hi[0] and lo[1] > lo[0]);
plot did = l;
plot did = s;

plot UpArrow = l;
plot DnArrow = s;

UpArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DnArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
did.SetPaintingStrategy( if close < open then UpArrow);
did.SetPaintingStrategy( if close > open then DnArrow);
did.AssignValueColor(if close > open then Color.GREEN else if close < open then Color.RED else Color.WHITE);
did.SetLineWeight(3);

I tried to update the code but not sure whats wrong. Sorry im new to this. If someone can help me would appreciate it
 
"Hammer candle script"
input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input shadowFactor = 2.0;

assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
assert(shadowFactor >= 0, "'shadow factor' must not be negative: " + shadowFactor);

def BodyHeight = BodyHeight();
def AverageBodyHeight = Average(BodyHeight, length);
def ErrMargin = 0.05 * AverageBodyHeight;
def IsShort = BodyHeight < bodyFactor * AverageBodyHeight;

plot Bullish = IsDescending(close, trendSetup) and
IsShort and
high - Max(open, close) <= ErrMargin and
Min(open, close) - low > shadowFactor * BodyHeight;

Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(4));
Bullish.SetLineWeight(2);

--------------------------------------------------------------------------------------------------------------
Updated script ( need help)

def lo = low;
def hi = high;
def vo = volume;

def l = If (hi[1] >= hi[0] and lo[1] < lo[0]);
def s = If (hi[1] <= hi[0] and lo[1] > lo[0]);
plot did = l;
plot did = s;

plot UpArrow = l;
plot DnArrow = s;

UpArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DnArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
did.SetPaintingStrategy( if close < open then UpArrow);
did.SetPaintingStrategy( if close > open then DnArrow);
did.AssignValueColor(if close > open then Color.GREEN else if close < open then Color.RED else Color.WHITE);
did.SetLineWeight(3);

I tried to update the code but not sure whats wrong. Sorry im new to this. If someone can help me would appreciate it

you have 2 plots, using the same variable name, did.
each plot has to have a unique variable.

delete these 2 lines
plot did = l
plot did = s

at the bottom, change every did. ,
to uparrow or dnarrow.
 
Try this... first time post for me. Used my code for a hammer and paint bar white instead of changing the arrow color. Also assume green volume bar is simply a close above the open and red is the opposite.

def HMA = MovingAverage(AverageType.HULL, close, 20);
def body = if close < open then open - close else if open < close then close - open else 0;
def lower = if close <= open then close - low else open - low;
def upper = if close <= open then high - open else high - close;
def total = high - low;

#Hammer: bullish reversal
def hammer = (close >= ((high + low) / 2)) and (open >= ((high + low) / 2)) and (lower >= (body * 2)) and (upper < (total * .1)) and (HMA < HMA[1]);

plot inside_bar_down = high[1] >= high and low[1] < low and close < open;
inside_bar_down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
inside_bar_down.AssignValueColor(Color.RED);
inside_bar_down.SetLineWeight(3);

plot inside_bar_up = high[1] >= high and low[1] < low and close > open;
inside_bar_up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
inside_bar_up.AssignValueColor(Color.GREEN);
inside_bar_up.SetLineWeight(3);

AssignPriceColor(if hammer > 0 then Color.WHITE else Color.CURRENT);
 
swap out to color arrows for hammer...

inside_bar_down.AssignValueColor(if hammer > 0 then Color.WHITE else Color.RED);

inside_bar_up.AssignValueColor(if hammer > 0 then Color.WHITE else Color.GREEN);
 
Can I ask if there's a script for to show Outside Bar and Inside Bar in TOS charts and change bar colour when this happens?

Is there a script for TOS Inside Bar followed by Outside Bar? Thank you.
 
Last edited by a moderator:
Hi MerryDay, just tried to load a pic of the chart but keep getting errors even though I followed the instructions.

I am trying to see if I can have an indicator as follows

1. Inside Bar [Candle Bar - Yellow]
2. Outside Bar [Candle Bar - White]
3. Inside Bar followed by Outside Bar [Background Shaded Yellow for these 2 bars]
4. Outside Bar followed by Inside Bar [Background Shaded Blue for these 2 bars]

Thanks very much.
 
Last edited:
@TieJiaoJie @roughsleeper
there are several examples listed below, in similar posts.

here is one i made , that counts how many bars were smaller before the outside bar
https://usethinkscript.com/threads/...st-65-most-recent-days.7483/page-2#post-72474
I am trying to see if I can do the the following. I have no computer language knowledge so very sorry to keep asking stupid questions. I am trying to add to the above indicator to have Outside Bar on it as well. Thank you very much.

# inside and outside bars
def inBar = low > low[1] and high < high[1];
def outBar = low < low[1] and high > high[1];
def holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];
def Outside Inside = what's should be the code similar to the above & plot wedge up as per below in a different colour.

def off = 1;
addchartbubble(lastbar[off] and holyGrail[off] and inbar[off], close, "Holy Grail" + "\nInbar", color.yellow, yes);
addchartbubble(lastbar[off] and holyGrail[off] and outbar[off], close, "Holy Grail" + "\nOutbar", color.yellow, yes);

plot hg2 = holygrail;
hg2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_up);
hg2.SetDefaultColor(Color.white);
hg2.setlineweight(3);
#
 
Hi,

I need help to get TOS code for Inside Bar followed by Outside Bar.

The following is the code for Outside Bar followed by Inside Bar.

def holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];

Thanks
 
I am trying to create a scan, chart indicator, and lower study that I could use for mobile to identify an inside day candle I have found some similar ones here and one off of hanntech website but I can't get this to be consistently accurate and the lower study doesn't work at all. I feel like I'm definitely missing something on the syntax

here is what i have for the lower
Ruby:
declare lower;



input offset = 1;
#def count = 2;


def range = high – low;
#def priorrange = high[1] – low[1];
def priorrange = range[1];
def nibsize = AbsValue(((open – close) / (open[1] – close[1]) - 1));
def sizeConstraint = AbsValue((range / priorrange) - 1) >= .5 and nibsize >= .5;
def hiLowConstraint = high <= high[1] and low >= low[1];
def inside_bar = sizeConstraint and hiLowConstraint;
rec insideBarRange = CompoundValue(1, if inside_bar then range else insideBarRange[1], Double.NaN);
#plot s = inside_bar && lowest(range,count);
def plotRightExpansionArea = !IsNaN(close[1]) and IsNaN(close[0]);
rec longEntry = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then high[offset] + 0.01 else Double.NaN else longEntry[1], Double.NaN);
rec longExit = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then longEntry + insideBarRange else Double.NaN else longExit[1], Double.NaN);

#plot longEntryLevel = longEntry;
#longEntryLevel.SetDefaultColor(Color.GREEN);
#plot longExitLevel = longExit;
#longExitLevel.SetDefaultColor(Color.DARK_GREEN);
#longExitLevel.SetPaintingStrategy(PaintingStrategy.DASHES);
#longExitLevel.SetLineWeight(1);

#dataplot
#ALERT
plot entryline = if close > longEntry then 0 else 1;
#1 = green , 0 = red
 
Last edited by a moderator:
I am trying to create a scan, chart indicator, and lower study that I could use for mobile to identify an inside day candle I have found some similar ones here and one off of hanntech website but I can't get this to be consistently accurate and the lower study doesn't work at all. I feel like I'm definitely missing something on the syntax
Looks like no contributor has been able to help you. It could be that it is not clear what you are asking or you did not provide enough information.

Please reply with a detail explanation of what you are trying to accomplish. or there is a risk that your post will be deleted due to inactivity.
Provide a marked-up screenshot of what a chart that displays what all your conditions would look like.
Questions without images are much less likely to get a response!
Unsure of how to upload screenshots to the forum, Here are directions.

When you are posting your question, please follow the guidelines found here:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-58016

Here are some other options.
gOqETY2.png


If you have this question, others will also. So if you find an answer to your question, could you post it to the forum? Your contribution will be helping a legion of like-minded traders and thinkscripters. Thanks!
 
Hello, @BenTen had previously shared the below code for identifying an inside bar. The below code adds an arrow on top of the inside candle. I was hoping someone could alter to code to instead just paint the inside bar candle white instead of adding an arrow on top of it.

I tried to ping Ben, but it does not appear he has been active for some time now. Appreciate any help and thanks in advance.

Existing Code Ben wrote, which adds a arrow on top of the inside bar candle:

Code:
# Inside Bar
# Mobius
# 8.7.2017

def inside = high < high[1] and low > low[1];
plot inside_bar = inside;
inside_bar.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
inside_bar.SetDefaultColor(Color.MAGENTA);
inside_bar.SetLineWeight(1);

Example of White Arrows on Inside Bars using code above:
WhiteIB.jpg


This request would be similar to what @SleepyZ provided in the below thread:

https://usethinkscript.com/threads/multi-timeframe-candles-overlay-for-thinkorswim.1425/post-79566

Code:
input Color_Candles_within_MTF_InsideBars = yes;
assignpriceColor(if [B]Color_Candles_within_MTF_InsideBars and[/B] insidebar then color.white else color.current);
/CODE]
 
Last edited:
Can anyone help me with my attempt here to simply identify outside (engulfing) bars but painting the bar / candle.

# Outside Bar Colored


def outsideBarID = high > high [1] and low < Low [1];

def bar = barNumber();

AssignPriceColor(if bar == outsideBarID

then color.plum

else color.current);
 

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
182 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