Close of last intraday bar

kvr53

New member
I use following codes to get the open of first intraday bar :

def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and getTime() <= RegularTradingEnd(getYYYYMMDD());
def RTHOpen = if RTH and !RTH[1] then open else RTHOpen[1];

How do I get the close of last intraday bar ? (9:30 - 15:59)
 
Solution
I use following codes to get the open of first intraday bar :

def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and getTime() <= RegularTradingEnd(getYYYYMMDD());
def RTHOpen = if RTH and !RTH[1] then open else RTHOpen[1];

How do I get the close of last intraday bar ? (9:30 - 15:59)

Try this

Capture.jpg
Code:
def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() <= RegularTradingEnd(GetYYYYMMDD());

def RTHClose = if RTH and !RTH[-1] then close else RTHClose[1];
AddChartBubble(RTH and !RTH[-1], low, RTHClose, Color.YELLOW, no);
I use following codes to get the open of first intraday bar :

def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and getTime() <= RegularTradingEnd(getYYYYMMDD());
def RTHOpen = if RTH and !RTH[1] then open else RTHOpen[1];

How do I get the close of last intraday bar ? (9:30 - 15:59)

Try this

Capture.jpg
Code:
def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() <= RegularTradingEnd(GetYYYYMMDD());

def RTHClose = if RTH and !RTH[-1] then close else RTHClose[1];
AddChartBubble(RTH and !RTH[-1], low, RTHClose, Color.YELLOW, no);
 
Solution
Is there a way to display the PrevClose bubbles on the right side of the chart and be able to show/disable the plots?

This should do what you requested

Screenshot-2022-10-12-063530.png
Ruby:
script philow {
    input n = 1;
    def ymd = GetYYYYMMDD();
    def ok = !IsNaN(close);
    def capture = ok and ymd != ymd[1];
    def dayCount = CompoundValue(1, if capture
                                    then dayCount[1] + 1
                                    else dayCount[1], 0);
    def thisDay = (HighestAll(dayCount) - dayCount) ;

    def cc = CompoundValue(1, if thisDay == n and secondstillTime(1600)>=0
                              then close
                              else cc[1], close);
    def ccnan   = if IsNaN(cc) then ccnan[1] else cc;
    plot ccplot = if thisDay == n and SecondsFromTime(1600) < 0
                  then Double.NaN
                  else if thisDay <= n
                  then (ccnan)
                  else Double.NaN;

}

#Plots of Highs/Lows/Opens/Closes based upon script...add more days using similar plot statements, increasing the value by 1

input showplots = yes;

plot C1 = philow(1).ccplot;
plot C2 = philow(2).ccplot;
plot C3 = philow(3).ccplot;
plot C4 = philow(4).ccplot;
plot C5 = philow(5).ccplot;


C1.setdefaultColor(color.yellow);
C2.setdefaultColor(color.yellow);
C3.setdefaultColor(color.yellow);
C4.setdefaultColor(color.yellow);
C5.setdefaultColor(color.yellow);

c1.sethiding(!showplots);
c2.sethiding(!showplots);
c3.sethiding(!showplots);
c4.sethiding(!showplots);
c5.sethiding(!showplots);

input showbubbles_Prior_OHLC = yes;
input n = 5;
def  n1 = n + 1;
def StartPlot = if showbubbles_Prior_OHLC == yes
                then (IsNaN(close[n]) and !IsNaN(close[n1]))
                else Double.NaN;


AddChartBubble(StartPlot,  Round(c1[n1], 2), "PC1-" + astext(Round(c1[n1], 2)), Color.YELLOW,  yes);
AddChartBubble(StartPlot,  Round(c2[n1], 2), "PC2-" + astext(Round(c2[n1], 2)), Color.YELLOW,  yes);
AddChartBubble(StartPlot,  Round(c3[n1], 2), "PC3-" + astext(Round(c3[n1], 2)), Color.YELLOW,  yes);
AddChartBubble(StartPlot,  Round(c4[n1], 2), "PC4-" + astext(Round(c4[n1], 2)), Color.YELLOW,  yes);
AddChartBubble(StartPlot,  Round(c5[n1], 2), "PC5-" + astext(Round(c5[n1], 2)), Color.YELLOW,  yes);
 

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