Get value of a particular candle

desiben

Member
im trying to find the value of the last green candle as its on the top bar of the chart.

For example: Lets say i have defined 'lastgreencandle' then how do I find the close of the 'lastgreencandle'?
 
Here is an example of how I got the closing price of today's trading day to display as a label on my chart.

Maybe this code can help you work on yours.

Code:
input aggregationPeriod = AggregationPeriod.DAY;
def close = close(period = aggregationPeriod);
AddLabel(yes, Concat("Day close = ", close), color.orange);

Another one: displaying the closing price of bullish engulfing candles as chart bubbles.

Code:
input length = 20;
input trendSetup = 3;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

def Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

AddChartBubble(Bullish, low, "Close = @ " + Round(close), Color.light_green, no);

Hope that helps.
 
Hello,

I'm an accomplished programmer, but new to Thinkscript.

I'm trying to figure out how to get the actual value of the most recent EMA crossover within the last X bars. All examples that I've seen show how to tell if there was a crossover - but I want the actual value of the EMA at that crossover point (or maybe even an offset in candles that the crossover happened so that I can fetch the value myself?)

Any help would be appreciated!
 
@jondecker76 Price Value at point of EMA Crossover

Code:
declare lower;
input fast = 20;
input slow = 200;
input price = CLOSE;
def null = double.NaN;
def S = expAverage(price, slow);
def F = expAverage(price, fast);
def CROSS = if F crosses S then S  else  CROSS[1];
plot scan =  CROSS;
AddLabel (yes, "Cross " +  (CROSS)  );
 
@jondecker76 Price Value at point of EMA Crossover

Code:
declare lower;
input fast = 20;
input slow = 200;
input price = CLOSE;
def null = double.NaN;
def S = expAverage(price, slow);
def F = expAverage(price, fast);
def CROSS = if F crosses S then S  else  CROSS[1];
plot scan =  CROSS;
AddLabel (yes, "Cross " +  (CROSS)  );

This is awesome. One quick follow-up question:

How could I create a label to show: Most recent EMA cross was X bars ago? (I can edit the text later)

The label helps me de-clutter my chart, so any help would be great!
 

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