How to request index of daily candle close

Viewed 207

I'm trying to get index of daily candle close.

I'm building an indicator which draws a horizontal line on 1 minute chart. for example since day's opening it draws line to 1440 bars forward (because 1 day has 1440 minutes) However when I change timeframe it's being broke. Is there a way to automatically spot index for close of daily candle? doesn't matter if I use 1m 5m 15m 1h 4h chart it will draw line until end of the day.

1 Answers

After hours of struggles and trying long codes I can't believe solution was that much simple. I was not sure if it's forbidden to answer my own question but I have never seen this question here before so I will answer. Maybe it will help someone in future. (if answering your own question is forbidden, I would like to ask admins to close question or delete what is needed)

---Calculations for pivot----
    day_op = request.security(syminfo.tickerid, "D", open, lookahead = barmerge.lookahead_on) //if daily open price changes it means new daily candle arrived
    day_cl = request.security(syminfo.tickerid, "D", time_close, lookahead = barmerge.lookahead_on) //get close time of daily bar 
    
    if ta.change(day_op) //if daily open price changed 
        a = line.new(time, pivot, day_cl , pivot, color=color.black, style=line.style_solid, xloc=xloc.bar_time)

here we draw new line "a" when new day started, it gets pivot calculations of previous day. it draws from time of day_opening until day_cl. (close time of the day) a warning if you use xlox=xloc.bar_index this line won't draw correctly!

Related