Pivot Points
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bandelier

//@version=5
indicator("Pivot Points", overlay = true)

prevClose = request.security(syminfo.tickerid, "D", close[1], gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on)
prevHigh = request.security(syminfo.tickerid, "D", high[1], gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on)
prevLow = request.security(syminfo.tickerid, "D", low[1], gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on)

pivot = (prevClose + prevHigh + prevLow) / 3

R1 = (pivot * 2) - prevLow

R2 = pivot + (prevHigh - prevLow)

R3 = prevHigh + (2*(pivot - prevLow))

S1 = (pivot * 2) - prevHigh

S2 = pivot - (prevHigh - prevLow)

S3 = prevLow - (2*(prevHigh - pivot))

plot(pivot, color = color.white)

plot(R1, color = color.red)
plot(R2, color = color.red)
plot(R3, color = color.red)

plot(S1, color = color.green)
plot(S2, color = color.green)
plot(S3, color = color.green)

PivotLabel = label.new(bar_index, pivot, text = "P", color = color.white)
R1Label = label.new(bar_index, R1, text = "R1", color = color.red)
R2Label = label.new(bar_index, R2, text = "R2", color = color.red)
R3Label = label.new(bar_index, R3, text = "R3", color = color.red)
S1Label = label.new(bar_index, S1, text = "S1", color = color.green)
S2Label =label.new(bar_index, S2, text = "S2", color = color.green)
S3Label = label.new(bar_index, S3, text = "S3", color = color.green)

label.delete(PivotLabel[1])
label.delete(R1Label[1])
label.delete(R2Label[1])
label.delete(R3Label[1])
label.delete(S1Label[1])
label.delete(S2Label[1])
label.delete(S3Label[1])