Turtle Soup Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kulturdesken
//@version=5
indicator("Turtle Soup", overlay=true)

period = 20

high_value = ta.highest(high, period)
low_value = ta.lowest(low, period)

high_candle = high == high_value
low_candle = low == low_value

prev_high_value = ta.highest(high[1], period)
prev2_high_value = ta.highest(high[2], period)
prev3_high_value = ta.highest(high[3], period)
prev4_high_value = ta.highest(high[4], period)

prev_low_value = ta.lowest(low[1], period)
prev2_low_value = ta.lowest(low[2], period)
prev3_low_value = ta.lowest(low[3], period)
prev4_low_value = ta.lowest(low[4], period)

no_prev_high_candle = not (high[1] == prev_high_value or high[2] == prev2_high_value or high[3] == prev3_high_value or high[4] == prev4_high_value)
no_prev_low_candle = not (low[1] == prev_low_value or low[2] == prev2_low_value or low[3] == prev3_low_value or low[4] == prev4_low_value)

plotshape(high_candle and no_prev_high_candle and no_prev_low_candle, title="Turtle Soup", location=location.abovebar, color=color.green, style=shape.cross, size=size.tiny)
plotshape(low_candle and no_prev_high_candle and no_prev_low_candle, title="Turtle Soup", location=location.belowbar, color=color.red, style=shape.cross, size=size.tiny)
