Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To reference the highest and lowest prices of the preceding day in Pine Script v5, you can use the security() function with the highest() and lowest() functions.

Here is an example code:

//@version=5
indicator("Yesterday's High/Low", overlay=true)

yesterday_high = security(syminfo.tickerid, "D", highest(high))
yesterday_low = security(syminfo.tickerid, "D", lowest(low))

plot(yesterday_high, color=color.green)
plot(yesterday_low, color=color.red)

In this code, we use the security() function to fetch the highest and lowest prices of the preceding day. The syminfo.tickerid argument specifies the symbol and the "D" argument specifies the timeframe (daily). The highest(high) and lowest(low) functions are used to find the highest and lowest prices.

We then plot the highest and lowest prices using the plot() function, with the color argument set to green for the highest price and red for the lowest price.

Note that this code only works for daily charts. If you want to reference the highest and lowest prices of the preceding week or month, you need to change the timeframe argument accordingly (e.g. "W" for weekly, "M" for monthly).