How do I calculate lot size with stop loss?

 

I just cannot figure this out in my head so I would really appreciate if someone can explain to me.

I want to calculate the best lot size based on a known number of pips stop loss.

I know I can use code like this:

double lots = AccountFreeMargin() * Risk/100 / ( StopLossPoints * MarketInfo( Symbol(), MODE_TICKVALUE ) );

Please can someone show me a real life worked example as I know this will help me understand.

E.g. with $5000 free margin, mini account with 200:1 leverage, 50 pip stop loss, and 2% risk

 
Use this would give you this and you would have found this
Reason: