Ask Your Question
0

How can I utilize Pine Script v5 to reference the highest and lowest prices of the preceding day?

asked 2023-07-18 15:21:14 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-07-18 15:49:01 +0000

lalupa gravatar image

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).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-18 15:21:14 +0000

Seen: 10 times

Last updated: Jul 18 '23