Candle Pivot and Stop Loss
// 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("Candle Pivot and Stop Loss", overlay=true)

// Calculate Current candle Pivot point
currentCandlePivot = (high[1] + low[1] + close[1]) / 3

// Calculate Current candle True Range
prevHighLowDiff = high[1] - low[1]
prevHighCloseDiff = high[1] - close[1]
prevLowCloseDiff = low[1] - close[1]
currentCandleTrueRange = math.max(prevHighLowDiff, math.max(prevHighCloseDiff, prevLowCloseDiff))

// Calculate Current candle Down Side stop-loss
downsideStopLoss = currentCandlePivot + currentCandleTrueRange

// Calculate Current candle Up Side stop-loss
upsideStopLoss = currentCandlePivot - currentCandleTrueRange

// Plotting the Current candle Pivot point and Stop Loss levels
plot(currentCandlePivot, color=color.blue, title="Current Candle Pivot")
plot(downsideStopLoss, color=color.red, title="Downside Stop Loss")
plot(upsideStopLoss, color=color.green, title="Upside Stop Loss")

