-1

I’m trying to get a fill between two horizontal lines. However, I also want these two lines to start at the begining of the trading day and stop in the future (at the ending of the trading day ideally). On one hand, line.new can plot lines in the future but can’t seems to work with fill. On the other hand, plot works with fill but can’t seem to be plot in from a point in the past to a point in the future… Anyone would know a solution for that ?

Thank you !

Cochon
  • 1

1 Answers1

0

Use the box() functions instead and set the bgcolor as the equivalent of a color fill.

lb = input(30)

hh = highest(high, lb)
ll = lowest(low, lb)

mid = avg(hh, ll)

var box box_up = box.new(left = na, top = na, right = na, bottom = na, border_color = #00000000)
var box box_dn = box.new(left = na, top = na, right = na, bottom = na, border_color = #00000000)

var line l_hh = line.new(x1 = na, y1 = na, x2 = na, y2 = na, color = color.white)
var line l_mid = line.new(x1 = na, y1 = na, x2 = na, y2 = na, color = color.white)
var line l_ll = line.new(x1 = na, y1 = na, x2 = na, y2 = na, color = color.white)

up_col = close > mid ? color.new(color.lime, 30) : #00000000
dn_col = close < mid ? color.new(color.red, 30) : #00000000

box.set_lefttop(box_up, left = bar_index - lb, top = hh)
box.set_rightbottom(box_up, right = bar_index, bottom = mid)
box.set_bgcolor(box_up, color = up_col)

box.set_lefttop(box_dn, left = bar_index - lb, top = mid)
box.set_rightbottom(box_dn, right = bar_index, bottom = ll)
box.set_bgcolor(box_dn, color = dn_col)

line.set_xy1(l_hh, x = bar_index - lb, y = hh)
line.set_xy2(l_hh, x = bar_index, y = hh)

line.set_xy1(l_mid, x = bar_index - lb, y = mid)
line.set_xy2(l_mid, x = bar_index, y = mid)

line.set_xy1(l_ll, x = bar_index - lb, y = ll)
line.set_xy2(l_ll, x = bar_index, y = ll)

With your condition, so as above with up_col you could do the condition something along the lines of

up_col = hh - ll >= 10 ? color.new(color.lime, 30) : #00000000

rumpypumpydumpy
  • 3,435
  • 2
  • 5
  • 10
  • I have very few knowledge in Pinescript. What I coded so far is copy/paste from existing scripts. I found Pivot Boxes [LM] by lmatl but he uses `bar.new` and I struggle to get the left and right sides plot like I want… Could you give me a example please ? I forgot to mention that I want the fill (or the box) only if the difference between two lines is >= 10. My lines are price lines like OHLC of daily period. – Cochon Aug 17 '21 at 12:16
  • Thanks for that code. I sligthly changed it and added `box.set_extend` because it is the only way I found to have the box start at the begining of the trading session while have it continued beyond actual price bar. I tried to work with `bar_index`, in vain. However, I’d rather have the right side of the box to stop at the end of the trading day (just like TradingView’s built-in Standard Pivot Point). If you have any clue of how to do it I would greatly appreciate. – Cochon Aug 18 '21 at 10:37