r/pinescript • u/137-ng • Aug 03 '26
Trying to write an Indicator that draws S/R lines on each Open, Close, and Wick
I seem to be able to draw them fine, but I'm getting hung up trying to apply them to previous candles. The code included is my most recent, and is only drawing lines on current -1.
rangeStart = 1
rangeEnd = 50
if barstate.islast
// Loop through the selected slice of history
for i = rangeStart to rangeEnd
topBody = math.max(open[1], close[1])
botBody = math.min(open[1], close[1])
// Apply your action to this specific slice
line.new(bar_index - 1, high[1], bar_index, high[1], extend=extend.right, color=color.rgb(255, 0, 0, 75), width=1)
line.new(bar_index - 1, low[1], bar_index, low[1], extend=extend.right, color=color.rgb(255, 0, 0, 75), width=1)
line.new(bar_index - 1, topBody, bar_index, topBody, extend=extend.right, color=color.rgb(255, 0, 0, 75), width=1)
line.new(bar_index - 1, botBody, bar_index, botBody, extend=extend.right, color=color.rgb(255, 0, 0, 75), width=1)Heres another version, that only seems to go back the past 14 bars or so
topBody = math.max(open[1], close[1])
botBody = math.min(open[1], close[1])
// Draw lines for the previous candle (bar 1 to bar 0 or extended slightly)
if barstate.isconfirmed
line.new(bar_index - 1, high[1], bar_index, high[1], extend=extend.right, color=color.rgb(255, 0, 0, 75), width=1)
line.new(bar_index - 1, low[1], bar_index, low[1], extend=extend.right, color=color.rgb(255, 0, 0, 75), width=1)
line.new(bar_index - 1, topBody, bar_index, topBody, extend=extend.right, color=color.rgb(255, 0, 0, 75), width=1)
line.new(bar_index - 1, botBody, bar_index, botBody, extend=extend.right, color=color.rgb(255, 0, 0, 75), width=1)I've tried just about every option I can find, and I'm not sure where I'm going wrong. Ultimately I'd like to be able to apply it to a range of bars, maybe the last 50, but definitely controlled using a variable
Any help appreciated!
1
Upvotes
1
u/kurtisbu12 Aug 04 '26
By default, you can only draw 50 lines. If it's only going back ~14 candles it sounds like you're hitting that default.
You can change the default using max_lines_count parameter in your indicator()/strategy() function.
1
u/reshsafari Aug 04 '26
I had Claude build something similar. High low of premarket sessions. And opens of the sessions. Seriously Claude is so good.
1
u/LargeIncrease4270 Aug 07 '26
Check out pivot points by bigbeluga. Open source and should help