Reputation: 57
Yesterday I was trying to create an indicator that creates a short line, in H1 candles.
Something like the Standard Pivot Point on TradingView.
Example:
Upvotes: 1
Views: 2985
Reputation:
You can also plot shorter horizontal lines by using the plot()
function and changing the color to na
(to "hide" the plotted line)
//@version=2
study("Horizontal line", overlay=false)
counter = nz(counter[1]) == 6 ? 0 : nz(counter[1]) + 1
line_color = counter < 5 ? orange : na
plot(10, color=line_color)
The nz(counter[1])
looks at the previous value (1 step back) of the counter
series and the nz()
function returns 0.0
in case there is no previous value of counter
(e.g. at the beginning of the market)
You can overlay this over the candle chart by changing the overlay
parameter of study()
to true
.
This is great in some cases, but unfortunately it causes problems with the automatic scale if you set the value of your line to 0
or na
, because the plotted line is still there, even though is invisible. I'm usually setting the value to close
or open
to work around this.
Upvotes: 1
Reputation: 2821
I have my implementation of pivot points where I draw some lines. Maybe that's not exactly what you're asking for, but I hope it'll be heplful for you:
//@version=3
study("Pivot Points, Traditional (today)", overlay=true)
daylyClose = security(tickerid, "D", close)
daylyHigh = security(tickerid, "D", high)
daylyLow = security(tickerid, "D", low)
pivot = (daylyClose + daylyHigh + daylyLow) / 3
r1 = pivot * 2 - daylyLow
r2 = pivot + (daylyHigh - daylyLow)
r3 = pivot * 2 + (daylyHigh - 2 * daylyLow)
r4 = pivot * 3 + (daylyHigh - 3 * daylyLow)
r5 = pivot * 4 + (daylyHigh - 4 * daylyLow)
s1 = pivot * 2 - daylyHigh
s2 = pivot - (daylyHigh - daylyLow)
s3 = pivot * 2 - (2 * daylyHigh - daylyLow)
s4 = pivot * 3 - (3 * daylyHigh - daylyLow)
s5 = pivot * 4 - (4 * daylyHigh - daylyLow)
plot(pivot, style= stepline)
plot(r1, style= stepline)
plot(r2, style= stepline)
plot(r3, style= stepline)
plot(r4, style= stepline)
plot(r5, style= stepline)
plot(s1, style= stepline)
plot(s2, style= stepline)
plot(s3, style= stepline)
plot(s4, style= stepline)
plot(s5, style= stepline)
Note1: my script works for intraday resolution - on daily resolutions it gets changed every day.
Note2: That's only works for existing bars - history and realtime. It cannot draw a line to the future.
Upvotes: 1