1

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. enter image description here

This is the result I am looking for :

enter image description here

I'd like :

  • to display today and yesterday pivot points.
  • that the lines starts from today until the end of the session
  • to write "PP, S1/S2/S3, R1/R2/R3" in front of the lines

Thanks for your advises

Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42
manny-
  • 129
  • 2
  • 10

2 Answers2

1

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)
Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42
  • So i've added this code line : "float vPP = na" at the beginning and then "plot(vPP, change(vPP) ? na : color.black, title="vPP", style = linebr, linewidth = width)". However it get this error : "Script could not be translated from: |B|float vPP = na|E| |B|." Any idea ? – manny- Nov 07 '20 at 20:07
  • 1
    I've edited my answer to include your code example. – Bjorn Mistiaen Nov 07 '20 at 20:32
0

try style = plot.style_linebr instead of style = line or

style = linebr
JSQC
  • 13
  • 6
  • "Error: Undeclared identifier `plot.style_linebr` " with the line "plot(vPP, color=black, title="vPP", style = plot.style_linebr, linewidth = width)" – manny- Nov 07 '20 at 16:03
  • what version are you using? maybe just style = linebr – JSQC Nov 07 '20 at 16:06
  • first solution gives this error : Error: Undeclared identifier `style_linebr` second solution gives no error, however the result is the same as the 1st picture I dont know about the version.. i'd say v3, because i've tried the function "line.new()" and it didn't work because it was not recognized – manny- Nov 07 '20 at 16:13
  • I guess linebr doesn"t solve the problem because there is no missing data ... – manny- Nov 07 '20 at 16:44