Hello and welcome new person

Just enter it all as one single array formula, something like

{=IF(A1<0,MAX(IF(...)),MAX(IF(...)))}