Question: I have a pine script to draw previous day high/open/low as shown below:

```
//@version=4
strategy("Plot Lines", overlay=true)

PDH = security(syminfo.tickerid,"D",high)
PDO = security(syminfo.tickerid,"D",open)
PDL = security(syminfo.tickerid,"D",low)

plot(PDH, title="High",color=color.red,linewidth=2,trackprice=true)
plot(PDO, title="Open",color=color.yellow,linewidth=2,trackprice=true)
plot(PDL, title="Low",color=color.green,linewidth=2,trackprice=true)

```

The script work well but I only want previous day to be shown and ignore the others day before previous day so that the chart will not be that messy.

This is what I get from the script above:
[![enter image description here](https://i.stack.imgur.com/sVIs9.png)](https://i.stack.imgur.com/sVIs9.png)

As you can see, it plot the PDH/PDO/PDL for every previous day, but I just want previous day (one day) only. Any help or advice will be greatly appreciated!

**New Edited**
[![enter image description here](https://i.stack.imgur.com/Nsez0.png)](https://i.stack.imgur.com/Nsez0.png)

**Result after apply the script**
[![enter image description here](https://i.stack.imgur.com/uKXjz.png)](https://i.stack.imgur.com/uKXjz.png)

Answer: 
Great answer by @vitruvius, but I wanted to add a little something.  

There's no need to draw lines and remove the old ones. You can just define them once, and move them on the last bar. Also, the values can be requested in one single `security()` call.

```
//@version=5
indicator("Plot Lines", overlay=true)

f_newLine(_color) => line.new(na, na, na, na, xloc.bar_time, extend.right, _color)

f_moveLine(_line, _x, _y) =>
    line.set_xy1(_line, _x,   _y)
    line.set_xy2(_line, _x+1, _y)

var line    line_open = f_newLine(color.yellow)
var line    line_high = f_newLine(color.red)
var line    line_low  = f_newLine(color.green)

[pdo,pdh,pdl] = request.security(syminfo.tickerid,"D", [open,high,low])

if barstate.islast
    f_moveLine(line_open, time, pdo)
    f_moveLine(line_high, time, pdh)
    f_moveLine(line_low , time, pdl)

```

Edit 1

```
//@version=5
indicator("Plot Lines", overlay=true)

f_newLine(_color) => line.new(na, na, na, na, xloc.bar_time, extend.right, _color)

f_moveLine(_line, _x, _y) =>
    line.set_xy1(_line, _x,   _y)
    line.set_xy2(_line, _x+1, _y)

var line    line_open = f_newLine(color.yellow)
var line    line_high = f_newLine(color.red)
var line    line_low  = f_newLine(color.green)

[pdo,pdh,pdl,pdt] = request.security(syminfo.tickerid,"D", [open[1],high[1],low[1],time[1]])

if barstate.islast
    f_moveLine(line_open, pdt, pdo)
    f_moveLine(line_high, pdt, pdh)
    f_moveLine(line_low , pdt, pdl)

```
You can use the `line()` function instead of `plot()`.

Draw the lines if it is the last bar, and delete the previous ones along the way.

```
//@version=4
study("Plot Lines", overlay=true)

PDH = security(syminfo.tickerid,"D",high)
PDO = security(syminfo.tickerid,"D",open)
PDL = security(syminfo.tickerid,"D",low)

var line l_pdh = na, var line l_pdo = na, var line l_pdl = na

if barstate.islast
    l_pdh := line.new(bar_index-1, PDH, bar_index, PDH, extend=extend.both, color=color.green)
    l_pdo := line.new(bar_index-1, PDO, bar_index, PDO, extend=extend.both, color=color.blue)
    l_pdl := line.new(bar_index-1, PDL, bar_index, PDL, extend=extend.both, color=color.red)

line.delete(l_pdh[1])
line.delete(l_pdo[1])
line.delete(l_pdl[1])

```

[![enter image description here](https://i.stack.imgur.com/FIjW9.png)](https://i.stack.imgur.com/FIjW9.png)