Rocky Smith
Rocky Smith

Reputation: 7

Finding previous day open and close without security function

I want to find previous day open and close without using security function. How do I do that?

Upvotes: 0

Views: 1294

Answers (1)

rumpypumpydumpy
rumpypumpydumpy

Reputation: 3803

//@version=5
indicator("Previous open and close", overlay = true)


new_day = ta.change(dayofweek) != 0

eod = time_close == time_close("D") and barstate.isconfirmed

var float daily_open = na
var float daily_close = na

if new_day
    daily_open := open

if eod
    daily_close := close


bgcolor(new_day ? color.new(color.green, 90) : na)
bgcolor(eod ? color.new(color.red, 90) : na)

prev_open = ta.valuewhen(new_day, daily_open[1], 0)
prev_close = ta.valuewhen(new_day, daily_close[1], 0)

plot(prev_open, color = color.lime)
plot(prev_close, color = color.red)

Upvotes: 1

Related Questions