Formula for lot size?

Hello, I am starting to trade (I know about stoploss,take profit, sell limit and such basic things though).
And as a general rule, I dont want more than 2% risk per trade, have been using a page’s tool to calculate the lot size each time.

However in the long run as I am testing strategies it becomes annoying having to use that page to calculate lot sizes each time.
So I was wondering, the website hosting that calculator must also use a formula to come up with those numbers, does anyne know what the general formula used there might be?
it’s likely something very widely known I would guess.

Sadly, no matter how deep I dig, the website doesnt leave a single hint on how to calculate the lot size there.
help?

What do you trade?

I use a tool for MT5 that calculates the lot-size for me if i put in the risk in % i want. This is the easiest way in my opinion, there are a few good tools for MT4 and MT5.

I just make sure that the margin per trade is close to 5% of my account

Your risk factor is 2% per trade. On $1,000 funds, 2% is $20 risk capital. If you set a 50 pip stop loss, and pip value is 10 cents, the stop loss is $5 in value. Divide $20 risk capital by $5 stop loss, and divide by 100 to calculate a dynamic lot-size, i.e. ($20 risk capital / $5 stop loss)/100 = 0.04 lots.