You are correct to use the reuqest.security()
function. The catch is, the historical values of dots
will be filled on your chart's timeframe. So, dots[1]
will refer to its previous value on your chart's timeframe.
Let's look at two examples where we request the daily open price while we are on the 6-hour timeframe. So, we will have a new value on every 4th candle.
Example 1 (barmerge.lookahead_on):
[daily_1, daily_2] = request.security(syminfo.tickerid, "D", [open, open[1]], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_on)
Variable |
Bar #1 |
Bar #2 |
Bar #3 |
Bar #4 |
Bar #5 |
Bar #6 |
Bar #7 |
Bar #8 |
Bar #9 |
Bar #10 |
Bar #11 |
daily_1 |
16978.38 |
na |
na |
na |
17093.53 |
na |
na |
na |
16886.81 |
na |
na |
daily_1[1] |
na |
16978.38 |
na |
na |
na |
17093.53 |
na |
na |
na |
16886.81 |
na |
daily_2 |
17165.39 |
na |
na |
na |
16978.38 |
na |
na |
na |
17093.53 |
na |
na |
In this example, daily_1[1]
will follow daily_1
on the next bar. So, its value will refer to daily_1
's value on the previous bar on your chart's timeframe. daily_2
will refer to the previous day's open price. It is what you think daily_1[1]
should do.
Example 2 (barmerge.lookahead_off):
[daily_1, daily_2] = request.security(syminfo.tickerid, "D", [open, open[1]], gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on)
Variable |
Bar #1 |
Bar #2 |
Bar #3 |
Bar #4 |
Bar #5 |
Bar #6 |
Bar #7 |
Bar #8 |
Bar #9 |
Bar #10 |
Bar #11 |
daily_1 |
16978.38 |
16978.38 |
16978.38 |
16978.38 |
17093.53 |
17093.53 |
17093.53 |
17093.53 |
16886.81 |
16886.81 |
16886.81 |
daily_1[1] |
17165.39 |
16978.38 |
16978.38 |
16978.38 |
16978.38 |
17093.53 |
17093.53 |
17093.53 |
17093.53 |
16886.81 |
16886.81 |
daily_2 |
17165.39 |
17165.39 |
17165.39 |
17165.39 |
16978.38 |
16978.38 |
16978.38 |
16978.38 |
17093.53 |
17093.53 |
17093.53 |
This example shows how the historical values are being filled.
Note:
This is a real example.
Ticker: BINANCE:BTCBUSD
Timeframe: 6h
Bar #1: Fri 02 Dec '22 00:00 UTC
Bar #11: Sun 04 Dec '22 12:00 UTC
You can check out the values if you simply add the following:
plotchar(daily_1, "daily_1", "")
plotchar(daily_1[1], "daily_1[1]", "")
plotchar(daily_2, "daily_2", "")