Inside and Outsidebars with horizontal lines

grapetux

Member
Hey folks, Need help with a simple code to only show the horizontal lines for inside and outside bars when they are present, not any other scenario. Below is the code I've put together which does show them, but it also plots the regular highs and lows from the 30min time frame
Thanks for the help

###
input aggregationPeriod = AggregationPeriod.thirty_MIN;
input length = 1;

plot DH= Highest(high(period = aggregationPeriod), length) ;

plot DL= Lowest(low(period = aggregationPeriod), length);

plot DH1= Highest(high(period = aggregationPeriod), length) ;

plot DL1= Lowest(low(period = aggregationPeriod), length);


def insidebar = DH<DH[1] and DL>DL[1] ;
def outsidebar = DH>DH[1] and DL<DL[1] ;

addlabel(yes, if insidebar[1] then " inside 30 " else if outsidebar[1] then " outside 30 " else " " , if insidebar[1] then color.dark_orange else if outsidebar[1] then color.dark_orange else color.light_gray);

DH.assignValueColor(if insidebar then color.magenta else color.white);
DL.assignValueColor(if insidebar then color.magenta else color.white);
DH1.assignValueColor(if outsidebar then color.blue else color.white);
DL1.assignValueColor(if outsidebar then color.blue else color.white);
 
Solution
Hey folks, Need help with a simple code to only show the horizontal lines for inside and outside bars when they are present, not any other scenario. Below is the code I've put together which does show them, but it also plots the regular highs and lows from the 30min time frame
Thanks for the help

###
input aggregationPeriod = AggregationPeriod.thirty_MIN;
input length = 1;

plot DH= Highest(high(period = aggregationPeriod), length) ;

plot DL= Lowest(low(period = aggregationPeriod), length);

plot DH1= Highest(high(period = aggregationPeriod), length) ;

plot DL1= Lowest(low(period = aggregationPeriod), length);


def insidebar = DH<DH[1] and DL>DL[1] ;
def outsidebar = DH>DH[1] and DL<DL[1] ;

addlabel(yes, if insidebar[1] then...
Hey folks, Need help with a simple code to only show the horizontal lines for inside and outside bars when they are present, not any other scenario. Below is the code I've put together which does show them, but it also plots the regular highs and lows from the 30min time frame
Thanks for the help

###
input aggregationPeriod = AggregationPeriod.thirty_MIN;
input length = 1;

plot DH= Highest(high(period = aggregationPeriod), length) ;

plot DL= Lowest(low(period = aggregationPeriod), length);

plot DH1= Highest(high(period = aggregationPeriod), length) ;

plot DL1= Lowest(low(period = aggregationPeriod), length);


def insidebar = DH<DH[1] and DL>DL[1] ;
def outsidebar = DH>DH[1] and DL<DL[1] ;

addlabel(yes, if insidebar[1] then " inside 30 " else if outsidebar[1] then " outside 30 " else " " , if insidebar[1] then color.dark_orange else if outsidebar[1] then color.dark_orange else color.light_gray);

DH.assignValueColor(if insidebar then color.magenta else color.white);
DL.assignValueColor(if insidebar then color.magenta else color.white);
DH1.assignValueColor(if outsidebar then color.blue else color.white);
DL1.assignValueColor(if outsidebar then color.blue else color.white);


this will find inside and outside bars.
can pick a MTF time

solid line is mother bar
dash line is smaller bar
cyan - inside bar - a big candle with a smaller candle after it
yellow - outside bar - a small candle with bigger candle after it

Code:
# inside_outside_lines_mtf

#https://usethinkscript.com/threads/inside-and-outsidebars-with-horizontal-lines.15391/
#Inside and Outsidebars with horizontal lines

#------------------------------------
def na = Double.NaN;
input agg = AggregationPeriod.THIRTY_MIN;

def hiagg = high(period = agg);
def loagg = low(period = agg);

#------------------------------
# inside bar - a big candle and smaller candle after it
def inside1 = hiagg > hiagg[-1] and loagg < loagg[-1];

plot inside_top1 = if inside1[0] then hiagg else na;
plot inside_top2 = if inside1[1] then hiagg[1] else na;
plot inside_bot1 = if inside1[0] then loagg else na;
plot inside_bot2 = if inside1[1] then loagg[1] else na;

inside_top1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_top1.SetDefaultColor(Color.CYAN);
inside_top1.HideBubble();
#inside_top2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_top2.SetStyle(Curve.medium_DASH);
inside_top2.SetDefaultColor(Color.CYAN);
inside_top2.HideBubble();

inside_bot1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_bot1.SetDefaultColor(Color.CYAN);
inside_bot1.HideBubble();
#inside_bot2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_bot2.SetStyle(Curve.medium_DASH);
inside_bot2.SetDefaultColor(Color.CYAN);
inside_bot2.HideBubble();

#-----------------------------

# outside bar - a small candle with big candle after it
def outside1 = hiagg < hiagg[-1] and loagg > loagg[-1];

plot outside_top2 = if outside1[0] then hiagg[-1] else na;
plot outside_top1 = if outside1[1] then hiagg[0] else na;
plot outside_bot2 = if outside1[0] then loagg[-1] else na;
plot outside_bot1 = if outside1[1] then loagg[0] else na;

outside_top1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_top1.SetDefaultColor(Color.yellow);
outside_top1.HideBubble();
#outside_top2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_top2.SetStyle(Curve.medium_DASH);
outside_top2.SetDefaultColor(Color.yellow);
outside_top2.HideBubble();

outside_bot1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_bot1.SetDefaultColor(Color.yellow);
outside_bot1.HideBubble();
#outside_bot2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_bot2.SetStyle(Curve.medium_DASH);
outside_bot2.SetDefaultColor(Color.yellow);
outside_bot2.HideBubble();
#

5 min chart
agg set to 30 min. 6 bars / agg period
solid line is mother bar
dash line is smaller bar

cyan - inside bar - a big candle with a smaller candle after it
yellow - outside bar - a small candle with bigger candle after it
a2dS9wd.jpg
 
Solution

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