Ask Your Question
1

What is the method for sketching a line x pips higher or lower than the closing price in TradingView Pine Script?

asked 2021-11-06 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-28 16:00:00 +0000

lakamha gravatar image

To sketch a line x pips higher or lower than the closing price in TradingView Pine Script, you can use the "offset" parameter in the plot() function. Here's an example code:

//@version=4
study("My Script")
pip_offset = input(10, "Pip Offset", step=1)

// Calculate the offset in decimal format
offset = pip_offset / syminfo.mintick

// Plot a line x pips above the closing price
plot(close + offset, color=color.blue)

// Plot a line x pips below the closing price
plot(close - offset, color=color.red)

In this code, you first define a input variable "pip_offset" that allows the user to specify the number of pips they want to offset the line by. Then, you calculate the offset in decimal format by dividing the pip offset by the minimum tick size for the current symbol. Finally, you use the plot() function to plot two lines: one x pips above the closing price (in blue) and one x pips below the closing price (in red), using the "offset" variable to specify the offset.

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: 2021-11-06 11:00:00 +0000

Seen: 11 times

Last updated: Jun 28 '21