It depends somewhat on the HT condition of the 17-4PH, but in general it is very similar in corrosion resistant to 304.
But that is assuming that both were properly heat treated and cleaned (especially free from any heat tint).
That said 17-4PH even in a lower strength condition (H1150) has a min yield strength of 115ksi min, and to near that with 304 would take some heavily cold worked rod.
I would rather use 17-4PH in the H1150 condition than cold worked 304.
That said there are other options, perhaps a duplex stainless (LDX2101). Even annealed these alloys will have a yield strength of 75ksi which may be enough, and they have better corrosion resistance, and don't require HT or cold work.
= = = = = = = = = = = = = = = = = = = =
P.E. Metallurgy, Plymouth Tube