0

I am working on a fairly simple thing but cannot make it work. The current bar close should be compared to the highest or the lowest price of a lookback period and a shape should be plotted if the closing price exceeds that price.

lookbackPeriod = input(5, "Lookback Period")
var int plotter = na

lowP = lowest(lookbackPeriod)
highP = highest(lookbackPeriod)

if close < lowP or close > highP
plotter := 1
else
plotter := 0

plotshape(plotter, title="shape", location=location.abovebar, 
color=color.green, style=shape.triangleup, size=size.small)

Somehow the plotshape function does not accept the series argument and i don't know why. Any hint would be much appreciated.

Thanks!

1 Answers1

0

The way your code is now your condition will never be true. This is because if the close is higher than "highP" or lower than "lowP" than that close is now "highP" or "lowP". You need to check if its higher or lower than highP[1] or lowP[1].

Also if you are using version5 of pinescript you need to use ta.highest and ta.lowest

//@version=5
indicator("My script", overlay = true)
lookbackPeriod = input(5, "Lookback Period")
var int plotter = na

lowP = ta.lowest(lookbackPeriod)
highP = ta.highest(lookbackPeriod)

if close < lowP[1] or close > highP[1]
    plotter := 1
else
    plotter := 0

plotshape(plotter, title="shape", location=location.abovebar, color=color.green, style=shape.triangleup, size=size.small)
smashapalooza
  • 932
  • 2
  • 2
  • 12