Reputation: 73
I am using Pinescript's request.security()
feature to retrieve a value that is an End of Day (EOD) value, i.e. the value is only a single value that is provided some time after market close. However, during market hours and for some time thereafter, Pinescript will plot the retrieved value on the chart by assuming it has the same exact value as the previous day's bar. The end result is that the last bar shows the same value as the previous bar even though the last bar's value is still unknown. This is obviously confusing or worse. To work around this I would like to identify when the last bar is NOT yet updated, then add a text label/note on the bar to tell the user it is pending an EOD update. I had hoped I could use barstate.isconfirmed
to identify when the update has occurred but according to the Pinescript v6 manual:
It is NOT recommended to use
barstate.isconfirmed
in request.security expression. Its value requested fromrequest.security
is unpredictable [link].
Another possible 'solution' might be to identify when the value is updated using ta.change
. I'd like to avoid that hack because there are times when two consecutive values would be identical, in which case this approach would not be able to identify that an update has occurred.
Upvotes: 0
Views: 52
Reputation: 73
I eventually came up with the following solution. When calling request.security()
for the delayed ticker symbol include dayofmonth
in the expression. This will retrieve the date of the latest value for the requested ticker symbol. For tickers with realtime data, the date will be the current date. For tickers that are delayed until after market hours (EOD), the date will correctly note the previous trading day until the ticker is updated after market close. For next business day (NBD) data, the date will correctly report the previous trading day when the data is updated. Assuming the main chart symbol is provided in real time, these dates can then be compared with the actual date taken from the dayofmonth()
function. A similar approach can be taken using time_close
.
Sample code is below along with the results from the data window:
indicator("My script")
[FRED,t1,d1] = request.security("FRED:BAMLH0A0HYM2", timeframe.period, [close, time_close, dayofmonth], ignore_invalid_symbol = true)
[s5tw,t2,d2] = request.security("S5TW", timeframe.period, [close, time_close, dayofmonth], ignore_invalid_symbol = true)
[spy,t3,d3] = request.security("SPY", timeframe.period, [close, time_close, dayofmonth], ignore_invalid_symbol = true)
// *************** Comparing day of month ***************
// Actual date
plot(dayofmonth(time_close), title="Actual date", display=display.data_window, precision=0)
// Next Business Day symbol
plot(d1, title="FRED", display=display.data_window, precision=0)
// End of Day symbol
plot(d2, title="S5TW", display=display.data_window, precision=0)
// Real time symbol
plot(d3, title="SPY", display=display.data_window, precision=0)
// *************** Comparing time of close ***************
// Actual date
plot(time_close, title="Actual Time", display=display.data_window, precision=0)
// Next Business Day symbol
plot(t1, title="FRED", display=display.data_window, precision=0)
// End of Day symbol
plot(t2, title="S5TW", display=display.data_window, precision=0)
// Real time symbol
plot(t3, title="SPY", display=display.data_window, precision=0)
Upvotes: 0