Every morning you open the 1 hour chart, find yesterday's high and low, and draw a horizontal line at each. Then you watch for the bars that poke through one of those lines and close back inside. You have done it so often that it takes thirty seconds and no thought. That is the sign it is a rule, and a rule you repeat by hand on every chart is a rule a script could draw for you, on every market, without the morning routine and without the day you forget. The hard part is not the code. It is that the rule only exists in your hands, and your hands make small choices you never noticed: wick or close, which time zone the day starts in, how long the line lasts. This guide shows how to get the rule out of your drawings and into words, check it with PineScripter's chart agent against the lines you already drew, and turn it into a Pine Script v6 indicator.
Short answer
Write the drawing down as a rule before you write any code. For each line, answer five questions: which bar or time it is anchored to, which price it uses (high, low, open or close), how long it lasts, when it is replaced by a new one, and what counts as price interacting with it. Then compare the written rule with the lines you already drew by hand, on several days, and fix whichever one is wrong. Once the two agree, the rule is a short script. For yesterday's high and low, that means tracking each day's range from the chart's own bars, plotting the finished range across the next day, and marking closed bars that trade through a level and close back inside it.
Key facts
- A drawing you repeat on every chart is an unwritten rule. Writing it down is the step that turns it into code, and the step most people skip.
- Five questions pin down almost any line: its anchor, its price, how long it lasts, when it is replaced, and what counts as an interaction.
- Small choices hide in hand-drawn lines. Wick or close, and which time zone the day starts in, can each move a level by a meaningful amount.
- PineScripter's chart agent reads the drawings already on the chart, up to 40 of them, each with its tool, whether you or the agent drew it, and its points as time and price, alongside the recent bars.
- The agent can redraw your rule on other days with the drawing tools, so you can compare its lines with yours before any code exists.
- The script below builds yesterday's high and low from the chart's own bars, so it needs no request.security call and never uses a bar that has not closed for its marks.
- A script that matches your hand-drawn lines on several days and markets is a script you can trust to draw them on the charts you did not check.
| Question | For a previous day high and low | What goes wrong if you skip it |
|---|---|---|
| Anchor | The whole of the previous calendar day | Lines drift to whatever range looked like "yesterday" |
| Price | The highest high and lowest low (wicks) | Closes give a narrower range that does not match your lines |
| How long it lasts | Across the whole of the next day | Lines run on forever and the chart fills up |
| When it is replaced | At the start of each new day, in the exchange time zone | The script and your lines disagree around midnight |
| Interaction | A closed bar trades through the level and closes back inside | Every touch, or every unfinished bar, gets marked |
A drawing you repeat is a rule you have not written down
Most traders have a few drawings they make on every chart: yesterday's high and low, the open of the week, the last swing before a big move, a round number. Each one feels like judgment, but if you ask why the line is where it is, the answer is almost always a rule: "it is the high of the previous day". The trouble with a rule that lives in your hands is that you cannot check it, you cannot run it on fifty markets, and you apply it slightly differently on a tired morning.
Turning it into an indicator removes all three problems, and it is usually less work than people expect. The code for yesterday's high and low is about twenty lines. What takes the time is discovering what your rule actually is, because the version in your head ("draw yesterday's high") leaves out choices your hands make without asking you.
Write the rule down with five questions
Start from one line you drew and answer five questions about it. The anchor: which bar, or which span of time, does the line come from? The price: is it a high, a low, an open, a close, or something computed? The lifetime: does the line run to the right edge forever, until the end of the day, or until price crosses it? The replacement: when does a new line take over, and in which time zone does that boundary fall? The interaction: what exactly are you watching for at the line, and does the bar have to have closed before it counts?
For the morning routine above, the answers are: the whole previous calendar day, its highest high and lowest low, drawn across the whole of the current day, replaced at midnight in the exchange's time zone, and a closed bar that trades through the level and closes back on the side it came from. The table near the top of this post lists the same answers next to what goes wrong when one is left vague. Writing them down this way often settles arguments you did not know you were having with yourself. Many people find they had been using the close of the day instead of its extreme on the days when a wick looked like noise, which is a different rule.
The time zone question deserves its own sentence, because it is the one that breaks most scripts that are meant to match hand-drawn lines. A day on a crypto chart starts at midnight in the exchange's time zone, which is UTC for crypto pairs on Binance. If you think of "yesterday" in your local time, your hand-drawn lines and any script will disagree on every day where the high or low printed in the hours between the two midnights.
Let the agent read your lines and say what they match
Before writing code, check the written rule against the lines you already drew. On PineScripter's chart this is a conversation with the chart agent. Draw your two lines the way you always do, then ask: "Look at my two horizontal lines on BTCUSDT 1h and tell me which bars' prices they match." The agent reads the chart, which includes the drawings already on that market (up to 40, each with its tool, whether you or the agent drew it, and its points as time and price) and the recent bars. It can then say whether your upper line sits on the highest high of the previous UTC day, on a close, or on neither.
Treat the answer as a second pair of eyes, not a verdict. It is describing your drawings against the bars, and it can be wrong, so check what it says against the chart yourself. The useful part is that it puts the mismatch into words: "your low line is at the low of the previous day in your local time, not in UTC" is the kind of finding that would otherwise only show up as a script that looks almost, but not quite, right.
Then go one step further and have it apply the rule where you did not draw. Ask it to draw the previous day's high and low for each of the last five days with horizontal rays. An AI cursor picks the tool in the drawing toolbar and clicks each level, and you can compare its lines with yours on the days you did draw. If they agree, the written rule is the rule you use. If they do not, fix the rule or fix your habit, then ask again. Every batch it draws can be undone from the chat in one click, and it only edits or removes your own drawings if you ask it to. The agent works on PineScripter's chart, on crypto spot markets, not on your TradingView chart.
Turn the rule into an indicator
With the five answers written down, the script follows them line by line. In the same chat you can describe the rule in plain English and PineScripter writes the Pine Script, checks it, and draws it on the chart, where you can put it next to the lines you drew. The version below is what that rule comes to. It tracks the current day's high and low from the chart's own bars, hands them over as "previous" when a new day starts, plots them as broken lines so each day gets its own segment, and marks closed bars that trade through a level and close back inside.
//@version=6
indicator("Previous day high and low", overlay = true)
newDay = dayofmonth != dayofmonth[1]
// Today's range so far, and yesterday's finished range.
var float dayHigh = na
var float dayLow = na
var float prevHigh = na
var float prevLow = na
if newDay
prevHigh := dayHigh
prevLow := dayLow
dayHigh := high
dayLow := low
else
dayHigh := na(dayHigh) ? high : math.max(dayHigh, high)
dayLow := na(dayLow) ? low : math.min(dayLow, low)
// na on the first bar of a day breaks the line, so each day gets its own segment.
plot(newDay ? na : prevHigh, "Previous day high", color.red, 2, plot.style_linebr)
plot(newDay ? na : prevLow, "Previous day low", color.teal, 2, plot.style_linebr)
// A closed bar that trades through yesterday's level and closes back inside it.
tookHigh = barstate.isconfirmed and high > prevHigh and close < prevHigh
tookLow = barstate.isconfirmed and low < prevLow and close > prevLow
plotshape(tookHigh, "Traded above and closed back below", shape.triangledown, location.abovebar, color.red, size = size.tiny)
plotshape(tookLow, "Traded below and closed back above", shape.triangleup, location.belowbar, color.teal, size = size.tiny)Each answer from the five questions has a home in it. The anchor and the replacement are the newDay test, which compares the day of the month with the previous bar's, in the exchange's time zone. The price is the running math.max and math.min of the wicks. The lifetime is the plot with plot.style_linebr, which is cut on the first bar of each day so yesterday's line ends where the next one begins. The interaction is the pair of conditions at the bottom, each guarded by barstate.isconfirmed so a bar is only marked once it has closed. The script needs an intraday chart: on a daily chart every bar is a new day, so there is no line to draw. The first day on the chart has no previous day, so it has no lines either.
Building it from chart bars, or asking for the daily series
There is a second common way to get yesterday's high and low in Pine Script: request.security on the daily timeframe, reading high[1] and low[1] with lookahead switched on. Written that way it does not repaint, and it gives the exchange's official daily bar even when your chart has not loaded the whole of the previous day. The version above builds the range from the chart's own bars instead. It needs no request.security call, it is easy to read, and it follows the same bars your eyes followed when you drew the lines by hand, which is the point of this exercise.
The trade-off is that a range built from chart bars only knows the bars on the chart. If the history starts halfway through a day, that first day's range is partial. Both versions are correct for what they measure. Pick the one whose answer to the five questions matches yours, and if you are not sure how request.security handles lookahead, the guide on how it works is the place to start before you swap one for the other.
Check the script against your hand-drawn lines
Put the indicator on the same chart as the lines you drew and check a few days by eye. The script's lines should sit exactly on yours. If one is off by a candle's wick, one of the five answers differs between the script and your hand. Then check the days you did not draw: switch market, switch to another intraday timeframe, and scroll back. A rule that matches on the days you checked and on a market you did not draw is a rule you can stop drawing by hand.
Replay is the last check, and it matters most for the marks. Step through a day bar by bar and watch when each triangle appears. It should appear only once its bar has closed, never on a bar that is still forming, and never on a bar before the level existed. That is what barstate.isconfirmed is there for. The marks describe what price did at yesterday's levels on the bars you loaded. They are a record of the past, not a reason to act.
Common mistakes when turning drawings into code
The first is coding the rule in your head instead of the rule in your drawings. Checking the written rule against lines you already drew, before writing code, catches most of these. The second is the time zone: a script that uses the exchange's day will disagree with lines drawn from your local day, and both will look plausible. The third is marking bars that have not closed. A bar that trades above yesterday's high and closes back below it is only known when it has closed, and a mark that appears and disappears during the bar is the kind of repainting that makes a script look better on a finished chart than it was live.
The last is letting the script grow past the rule. Once the lines are automatic, it is tempting to add a filter, then a colour, then a condition. Each addition is a new rule. Write it down with the same five questions, check it against the chart the same way, and only then add it to the code.
Frequently asked questions
Can I turn my TradingView drawings into a Pine Script indicator?
Not directly: Pine Script cannot read the drawings on a chart. What you can do is write down the rule behind the drawings (anchor, price, lifetime, replacement and interaction) and code that rule, so the indicator draws the same lines for you on every chart.
How do I plot the previous day high and low in Pine Script?
Either track each day's high and low from the chart's own bars and plot the finished range across the next day, as in the script in this post, or use request.security on the daily timeframe with high[1] and low[1] and lookahead switched on. Both avoid repainting when written that way.
Why do my script's lines not match the ones I drew?
Usually one of two things. The script uses a different price than your hand did (close instead of the wick, or the other way round), or a different day boundary (the exchange's time zone instead of your local one). Write down your rule with the five questions and compare it with the code.
Can an AI read the lines I drew on a chart?
PineScripter's chart agent can read the drawings on PineScripter's chart, on crypto spot markets: each drawing's tool, whether you or the agent drew it, and its points as time and price, alongside the recent bars. It can describe what your lines match and redraw the rule on other days while you watch its cursor. It does not read your TradingView chart, and it does not say what to trade.
Does the previous day high and low indicator repaint?
The lines use only finished days, and the marks are guarded by barstate.isconfirmed, so a mark only appears once its bar has closed. The lines for the current day are fixed from its first bar onward, because they describe the previous day.
The practical takeaway
The lines you draw every morning are a rule that only your hands know. Write it down with five answers: the anchor, the price, how long the line lasts, when it is replaced, and what counts as price interacting with it. Check those answers against the lines you already drew, with the agent reading your drawings and redrawing the rule on the days you skipped. When the written rule and your lines agree, the script is short, and it will draw the same lines on every market without the morning routine.
The chart agent, the drawing toolbar and the editor that turns your rule into a script all live in one chat in PineScripter. Draw the lines once, ask the agent what they match, then describe the rule and get the indicator that draws it on every chart.
Sources
- Pine Script v6 reference: dayofmonth
- Pine Script v6 reference: plot.style_linebr
- Pine Script v6 reference: barstate.isconfirmed
- Pine Script v6 reference: request.security
Related reading: zones drawn from swing points, anchoring a fib by a rule, how request.security works, barstate.isconfirmed and unfinished bars, bar replay.
Disclaimer: PineScripter is a coding tool for Pine Script development. It does not provide financial advice and does not guarantee trading profits. Always backtest strategies thoroughly and understand the risks before live trading.