Hold Up A Second! (Demo)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Electrified

//@version=5

indicator("Hold Up A Second!", "HoldUp", overlay = true)
import Electrified/LabelHelper/7 as LH

rejectionsMajor = array.new_string()
rejectionsMinor = array.new_string()

rejMAJOR(string message, bool condition) =>
    if(condition)
        array.push(rejectionsMajor, message)
    condition

rejMinor(string message, bool condition) =>
    if(condition)
        array.push(rejectionsMinor, message)
    condition

rsi = ta.rsi(hlc3, 7)
    
rejMAJOR("Overbought!", rsi > 80)
rejMinor("Last two bars declining", close[0] < close[1] and close[1] < close[2])

joinLines(string[] values) =>
    size = array.size(values)
    if size == 0
        na
    else 
        result = ""
        for i = 0 to size - 1
            result := result + array.get(values, i) + '\n'
        result

rejMajorReasons = joinLines(rejectionsMajor)
rejMinorReasons = joinLines(rejectionsMinor)
rejReasons = (na(rejMajorReasons) ? "" : rejMajorReasons) + (na(rejMinorReasons) ? "" : rejMinorReasons)

rejLabel = LH.add(close, na(rejMajorReasons) ? " ⚠ " : " ✖ ", na(rejMajorReasons) ? color.orange : color.red, offset = 1, tooltip = rejReasons)
if rejReasons == ""
    label.delete(rejLabel[0])