1

Sorry to pester the forum here with more basic questions (I really am lost when it comes to pine script). So, currently I'm plotting the highs of all weekly red candles, however after reading through the documentation I realized that I'm unable to extend the lines across the screen using plot().

So I'm wondering if there is some way to do this with lines or I'm just missing something. Also I only need it to mark the past 20/30 red candles rather than all of them.

Here's what I got so far (With thanks to a fellow user!):

indicator("My script", overlay=true)

redCandle = (close < open)
timeFrame = input.timeframe("W", title="Time Frame")

[d_h, d_red] = request.security(syminfo.tickerid, timeFrame, [high, redCandle], lookahead=barmerge.lookahead_on)

plot(d_red ? d_h : na, style=plot.style_circles, color=color.green, linewidth=2)

enter image description here

Here is how it looks visually as well at the moment.

SomeGuy74
  • 27
  • 4

1 Answers1

1

You can create a line whenever there is a new red weekly candle with extend=extend.right. Then you can delete the previous lines as you wish with line.delete().

Below example will only keep one line on your chart and delete the previous one as it creates a new one.

if (d_red)
    l = line.new(bar_index, d_h, bar_index+1, d_h, extend=extend.right, color=color.red)
    line.delete(l[1])
vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • Thanks! Do you know how I would go about adding lines to more previous candles as well? I was able to get it showing more previous lines but they would only show on the 1 week timeframe and only the first line would exist on the 1 minute. – SomeGuy74 Aug 30 '22 at 13:58
  • 1
    You can use an array. I'm not sure how many weeks can be represented on the 1 minute chart. There is a limit for the number of bars you can have on your chart. Maybe it's because of that. – vitruvius Aug 30 '22 at 14:05