Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.