2

I've built a custom indicator and I've plotted them using dots on top of candles. When a dot meets a certain criteria with another dot, I draw a trend line connecting them. That works..

What I would like to do is augment these lines from higher timeframes since I typically trade on the 5m. Meaning, if these dots on the daily timeframe meet the criteria, I'd like the line to be drawn on the daily but I should be able to see as well when I'm on the 5m timeframe.

I've tried leveraging request.security like so..

dots = request.security(syminfo.tickerid, "D", calcDots(high), gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_on)

And when I plot dots I'll get only the single dot from the daily only on the 5m view I'm on.. which is fine. But when I go do dots[1] it's not the actual previous dot from the daily chart. Perhaps my understand of request.security isn't right and there's something else I need to do to access or run my code against that higher timeframe data?

vitruvius
  • 15,740
  • 3
  • 16
  • 26
bdoooh
  • 21
  • 1

1 Answers1

3

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", "")
vitruvius
  • 15,740
  • 3
  • 16
  • 26