Only display on current candle

FateOwnzYou

Active member
VIP
VIP Enthusiast
I am trying to make a certain number only display on the current candle but having difficulty coming up with a condition for it. I dont want this number to show on every candle in the past, only on the current. I just need a condition that would be true on the current candle, but none of the past, anyone have a quick condition in back of their head that I cannot think of?
 
Solution
@FateOwnzYou Sorry, I didn't want to step on @BenTen's convo w/you. I love this snippet of code:

Add A Chart Bubble TO Current Candle:

Java:
addchartBubble(isnan(close[-1]), text = close, "price location" = HIGH, color = Color.ORANGE);
Could you post the code that you're working on? That would be helpful for those wanting to tackle the problem.
 

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

Just really need a condition of anything, any certain code. But ya, I need the latest number to be displayed on ONLY the current bar of this script

Code:
def SetUpCount = CompoundValue(1, if close > close[4]
                 then SetUpCount[1] + 1
                 else if close < close[4]
                 then 0
                 else SetUpCount[1], 1);

plot Count = setupcount;
     count.SetPaintingStrategy(PaintingStrategy.Values_Above);
     Count.Setdefaultcolor(color.cyan);

So in the "plot" i need to make it a condition instead of just declaring "setupcount", I have tried

plot Count = if !setupcount[-1] then setupcount else double.nan

which would be checking if a value was there before that candle even formed and if there was no value, then it should plot it on the latest candle, but apparently there is a value on a futures candle that hasnt formed yet, which is odd
 
i would like to expand on that solution and offer another.
the reason this works , is that there are no candles with a high value, after the last bar. so 'price location' has an error after the last candle and causes addchartbubble() not to be drawn.
Code:
addchartBubble(isnan(close[-1]), text = close, "price location" = HIGH, color = Color.ORANGE);

after the last candle, there are placeholders for undrawn candles.
if constants are used in the bubble function, multiple bubbles will be drawn after the last candle.
Code:
addchartBubble(isnan(close[-1]), 80, "zzz", Color.ORANGE, yes);

here is an alternative code, that is true on the last candle. it checks if the current candle close is valid and if the next one is an error.
Code:
addchartBubble(!isnan(close[0]) and isnan(close[-1]), high, close, Color.ORANGE, yes);

from that code, you can add a constant, to pick a candle, that is x candles before or after the last one.
Code:
# plots a bubble x bars after last bar
input bars_in_future = 3;
def bif = bars_in_future;
def cls = close;
def x = isNaN(cls[bif]) and !isNaN(cls[bif+1]);
def vert = cls[bif+1];
AddChartBubble(x, vert, vert, color.white, yes);

kCsoRK9.png
 
Last edited:
Hello everyone,

I was wondering if anyone knew how to hide a plot past the current day. I have a script I have been playing with but it draws the plot out to the right edge of the chart, and it would make it easier to read if the line plot just ended at the current bar on a daily chart.

Thanks so much!
 
There was no "full code". This thread is just a discussion of best coding practices for PLOT statements.
Understood. I wish PC version was like Android where there is a line on the chart that shows you where the current price is on the latest candle. But I edited the code a bit and added that very last part to it, at least those lines kinda get the job done, not very clean however it leaves a trail of lines from previous candles:

# plots a bubble x bars after last bar
input bars_in_future = 3;
def bif = bars_in_future;
def cls = close;
def x = isNaN(cls[bif]) and !isNaN(cls[bif+1]);
def vert = cls[bif+1];
def z = cls[bif+1];
#AddChartBubble(x, vert, vert, color.white, yes);

#addchartBubble(isnan(close[-1]), text = close, "price location" = HIGH, color = Color.ORANGE);

#addchartBubble(!isnan(close[0]) and isnan(close[-1]), high, close, Color.ORANGE, yes);

plot currentpricelevel = z;

#--------------------------------------------------------------
currentpricelevel.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
currentpricelevel.SetDefaultColor(Color.white);
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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