Reputation: 15
I'm trying to write down the open and close price of each day, namely I want to write it down day by day and hence that Monday will write down the open close for Monday into a var variable and Tuesday will write down the open close for Tuesday. I will then put these values into an array for each day, which I'm able to do, but I can't come up with a method to get this data efficiently. I've already tried various combinations with dayofweek, but I'm failing.
Upvotes: 0
Views: 1185
Reputation: 3803
indicator("Daily open/close arrays", overlay = false)
var float[] monday_opens = array.new_float()
var float[] monday_closes = array.new_float()
var float[] tuesday_opens = array.new_float()
var float[] tuesday_closes = array.new_float()
var float[] wednesday_opens = array.new_float()
var float[] wednesday_closes = array.new_float()
var float[] thursday_opens = array.new_float()
var float[] thursday_closes = array.new_float()
var float[] friday_opens = array.new_float()
var float[] friday_closes = array.new_float()
var float[] saturday_opens = array.new_float()
var float[] saturday_closes = array.new_float()
var float[] sunday_opens = array.new_float()
var float[] sunday_closes = array.new_float()
new_day = ta.change(dayofweek) != 0
eod = time_close == time_close("D") and barstate.isconfirmed
if new_day
if dayofweek == dayofweek.monday
array.unshift(monday_opens, open)
else if dayofweek == dayofweek.tuesday
array.unshift(tuesday_opens, open)
else if dayofweek == dayofweek.wednesday
array.unshift(wednesday_opens, open)
else if dayofweek == dayofweek.thursday
array.unshift(thursday_opens, open)
else if dayofweek == dayofweek.friday
array.unshift(friday_opens, open)
else if dayofweek == dayofweek.saturday
array.unshift(saturday_opens, open)
else if dayofweek == dayofweek.sunday
array.unshift(sunday_opens, open)
if eod
if dayofweek == dayofweek.monday
array.unshift(monday_closes, close)
else if dayofweek == dayofweek.tuesday
array.unshift(tuesday_closes, close)
else if dayofweek == dayofweek.wednesday
array.unshift(wednesday_closes, close)
else if dayofweek == dayofweek.thursday
array.unshift(thursday_closes, close)
else if dayofweek == dayofweek.friday
array.unshift(friday_closes, close)
else if dayofweek == dayofweek.saturday
array.unshift(saturday_closes, close)
else if dayofweek == dayofweek.sunday
array.unshift(sunday_closes, close)
Upvotes: 1