Label to only appear if true

cappermac

New member
Code:
def isInsideBar = high < high[1] and low > low[1];
AssignPriceColor(if isInsideBar then Color.YELLOW else Color.CURRENT);

I am trying to have the code above appear as a label, only if true, when x number of days/candles is true. Otherwise no label is shown. And a WL if it's possible. Thank you.
 
Solution
Sorry was trying to see if this could show previous day inside bar as well if that helps.

I think this may be more what you wanted. There are optional labels and bubbles that will only display when true.

There is a current vs prior input. The current will include today's inside bar, if any. The prior will exclude it.

The input xbarsinside will then test the sum function to see if there are at least that number in the input in_xdays lookback. If true, then the label and/or bubble will display.

Ruby:
input xbarsinside = 2;
input in_xdays    = 5;

input agg        = AggregationPeriod.DAY;
def isInsideBar  = high(period = agg) < high(period = agg)[1] and
                   low(period = agg) >...
Code:
def isInsideBar = high < high[1] and low > low[1];
AssignPriceColor(if isInsideBar then Color.YELLOW else Color.CURRENT);

I am trying to have the code above appear as a label, only if true, when x number of days/candles is true. Otherwise no label is shown. And a WL if it's possible. Thank you.

Added optional label and bubble for you

Capture.jpg
Ruby:
def isInsideBar = high < high[1] and low > low[1];
AssignPriceColor(if isInsideBar then Color.YELLOW else Color.CURRENT);

input showlabel = yes;
AddLabel(showlabel and isInsideBar, "WL", Color.YELLOW);
input showbubble = yes;
addchartBubble(showbubble and isnan(close[2]) and !isnan(close[3]) and isinsidebar[3],close[3],"WL", color.yellow);
 
Sorry was trying to see if this could show previous day inside bar as well if that helps.

I think this may be more what you wanted. There are optional labels and bubbles that will only display when true.

There is a current vs prior input. The current will include today's inside bar, if any. The prior will exclude it.

The input xbarsinside will then test the sum function to see if there are at least that number in the input in_xdays lookback. If true, then the label and/or bubble will display.

Ruby:
input xbarsinside = 2;
input in_xdays    = 5;

input agg        = AggregationPeriod.DAY;
def isInsideBar  = high(period = agg) < high(period = agg)[1] and
                   low(period = agg) > low(period = agg)[1];
input pricecolor = yes;
AssignPriceColor(  if !pricecolor
                   then color.current       
                   else if isInsideBar
                   then Color.YELLOW else Color.CURRENT);

#Current includes inside bar today; Prior excludes today's inside bar, if any
input display        = {default current, prior};
def xdaysinside      = Sum(isInsideBar, in_xdays) >= xbarsinside;
def xpriordaysinside = Sum(isInsideBar[1], in_xdays) >= xbarsinside;

input showlabels = yes;
AddLabel(showlabels and display == display.current and xdaysinside, "Current", Color.YELLOW);
AddLabel(showlabels and display == display.prior and xpriordaysinside, "Prior", Color.YELLOW);

input showbubbles = yes;
AddChartBubble(showbubbles and IsNaN(close[2]) and !IsNaN(close[3]) and display == display.current and xdaysinside[3], close[3], "Current", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[2]) and !IsNaN(close[3]) and display == display.prior and xpriordaysinside[3], close[3], "Prior", Color.YELLOW);
;
 
Solution

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
283 Online
Create Post

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