Let say,

Account Balance / Free Margin : $200

Leverage : 1000

Currency Pair : GBPUSD

Account Currency : USD

Currently i am using : https://www.hfm.com/int/en/calculators/position-size-calculator and this show accurate Lot size but i am looking for formula so i can code into my EA.

How can i calculate the Maximum Lot size it can take. What are the formula or code to calculate?