SgjoeLibrary
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © The_Brit
// Last updated 15th November, 2021
//@version=5

// @description Custom functions  
library("SgjoeLibrary", true)

// Custom Functions {

// @function Permits a condition to be used with highest(high,condition)
// @param float _high_series The High for the condition 
// @param float _when The condition such as close > high[1]
// @returns The high(s) at the point(s) the condition was true
export highest_when(float _high_series, bool _when) =>
    var float _high = na
    _high := _high_series > _high or _when ? _high_series : _high
    _high

// @function Permits a condition to be used with lowest(low,condition) 
// @param float _low_series The Low for the condition 
// @param float _when The condition such as close < low[1]
// @returns The low(s) at the point(s) the condition was true
export lowest_when(float _low_series, bool _when) =>
    var float _low = na
    _low := _low_series < _low or _when ? _low_series : _low
    _low

// Breakouts can be achieved using [1] on the end
// or can keep within boundaries by removing [1] on end

// Example highest_when(high, close > high[1])[1]
// or lowest_when(low, close < low[1])[1]

// USE FUNCTION EXAMPLE
hw = highest_when(high, close > high[1])[1] 
lw = lowest_when(low, close < low[1])[1] 
plot(hw, title='Conditional Highest Highs', color=color.new(color.green, 0), linewidth=1, style=plot.style_linebr)
plot(lw, title='Conditional Lowest Lows', color=color.new(color.red, 0), linewidth=1, style=plot.style_linebr)
// }