I'm using charts on TradingView and I'd like to draw horizontal lines. The horizontal lines are the Pivot Points.
I've calculated them and each values is stocked in a variable.
width = input(2, minval=1)
xHigh = security(tickerid,"D", high[1])
xLow = security(tickerid,"D", low[1])
xClose = security(tickerid,"D", close[1])
vPP = (xHigh+xLow+xClose) / 3
vR1 = vPP+(vPP-xLow)
vS1 = vPP-(xHigh - vPP)
vR2 = vPP + (xHigh - xLow)
vS2 = vPP - (xHigh - xLow)
vR3 = xHigh + 2 * (vPP - xLow)
vS3 = xLow - 2 * (xHigh - vPP)
I've tried to use this line to do the job
plot(vPP, color=black, title="vPP", style = line, linewidth = width)
But from one day to another, the line doesn't cut. So it's not looking good. See the picture.
This is the result I am looking for :
I'd like :
Thanks for your advises
To remove the connecting line, you have to use color na
when the value changes.
For a code example, see the answer of PineCoders-LucF to one of my questions Plotting manual levels for daily high,low,close
Edit: Your code example, modified to work as you intended.
//@version=4
study("My Script", overlay=true)
width = input(2, minval=1)
xHigh = security(syminfo.ticker,"D", high[1])
xLow = security(syminfo.ticker,"D", low[1])
xClose = security(syminfo.ticker,"D", close[1])
vPP = (xHigh+xLow+xClose) / 3
vR1 = vPP+(vPP-xLow)
vS1 = vPP-(xHigh - vPP)
vR2 = vPP + (xHigh - xLow)
vS2 = vPP - (xHigh - xLow)
vR3 = xHigh + 2 * (vPP - xLow)
vS3 = xLow - 2 * (xHigh - vPP)
plot(vPP, color=change(vPP) ? na : color.black, title="vPP", style = plot.style_linebr, linewidth = width)
As requested in the comments, code for @version=3.
Remark: You should really use @version=4 to access the latest Pine script capabilities.
//@version=3
study("My Script", overlay=true)
width = input(2, minval=1)
xHigh = security(tickerid,"D", high[1])
xLow = security(tickerid,"D", low[1])
xClose = security(tickerid,"D", close[1])
vPP = (xHigh+xLow+xClose) / 3
vR1 = vPP+(vPP-xLow)
vS1 = vPP-(xHigh - vPP)
vR2 = vPP + (xHigh - xLow)
vS2 = vPP - (xHigh - xLow)
vR3 = xHigh + 2 * (vPP - xLow)
vS3 = xLow - 2 * (xHigh - vPP)
plot(vPP, color=change(vPP) ? na : black, title="vPP", style = linebr, linewidth = width)