Three Candle Rolling Pivot Range
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sabarijegan

//@version=5
indicator("Three Candle Rolling Pivot Range", overlay=true)

// Calculate rolling pivot range for the last three candles
c = input(3, title="Number of Previous Candles")
rolling_pivot = (high[c] + low[c] + close[c]) / 3
second_number = (high[c] + low[c]) / 2
pivot_differential = rolling_pivot - second_number
range_high = rolling_pivot + pivot_differential
range_low = rolling_pivot - pivot_differential

// Plot pivot range
plot(range_high, color=color.green, linewidth=2, title="Rolling Pivot Range High")
plot(rolling_pivot, color=color.blue, linewidth=2, title="Rolling Pivot")
plot(range_low, color=color.red, linewidth=2, title="Rolling Pivot Range Low")

// Entry conditions
long_entry = close > range_high and close[1] > range_high[1]
short_entry = close < range_low and close[1] < range_low[1]

// Plot entry signals
plotshape(series=long_entry, color=color.green, style=shape.triangleup, location=location.belowbar, size=size.small, title="Long Entry")
plotshape(series=short_entry, color=color.red, style=shape.triangledown, location=location.abovebar, size=size.small, title="Short Entry")
