Firstly, define what is "ruin" here - do you mean the number of tail (loss) observed is exceeding a certain number (the initial wealth)?

Secondly, do you know the probability of success/failure in each trial before you playing the game?

Thirdly, you need to define an objective function to maximize before finding the corresponding optimal stopping rule.