Candlestick OB Finder
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © simwai

//@version=5
indicator(title='Candlestick OB Finder', overlay=true)

bool isReverted = input.bool(false, 'Is logic reverted?')

bool isCurrentBarGreen = open[1] < close[1] 
bool isCurrentBarRed = open[1] > close[1]

bool isLastBarGreen = open[2] < close[2]
bool isLastBarRed = open[2] > close[2]
    
float currentGreenBarBody = close[1] - open[1]
float currentRedBarBody = open[1] - close[1]
        
float lastGreenBarBody = close[2] - open[2]
float lastRedBarBody = open[2] - close[2]

bool shortPlotCondition = isReverted ? (isLastBarRed and isCurrentBarGreen) and (currentGreenBarBody > (4 * lastRedBarBody)) : (isLastBarGreen and isCurrentBarRed) and (currentGreenBarBody < (4 * lastRedBarBody))
plotshape(shortPlotCondition, color=color.orange, location=location.abovebar, style=shape.circle)

bool longPlotCondition = isReverted ? (isLastBarGreen and isCurrentBarRed) and (currentGreenBarBody < (4 * lastRedBarBody)) : (isLastBarRed and isCurrentBarGreen) and (currentGreenBarBody > (4 * lastRedBarBody))
plotshape(longPlotCondition, color=color.lime, location=location.belowbar, style=shape.circle)
