Calculation of no. of lots based on available capital

I want to know how to calculate no. of lots based on available capital
For ex - if i have a capital of 20k & i want to buy nifty 50 ATM , lets say that the strike price of the ATM is 95 Rs, so the cost price of the ATM will be (strike price * Lot size(50)) 95*50 = 4750 , so logically i know that 4 lots can be bought ( capital available / cost price of the ATM) 20000/4750 = 4.21. But i what to know which conditions should i add in my tradetron startegy so that it would calculate by itself.

Will this work?