I'm just trying to figure out what exactly is happening in the above code segment.
Why is the free margin divided by 8000?
Is line two calculating the maximum amount of "0.1" lots to a maximum of 15?
Why is my lot size 0.1?
It first calculates a percentage of ACCOUNT_MARGIN_FREE by dividing it with 8000.
Then it calculates min and max value to keep it between the bandwidth.
Then it normalizes to a 2 digit double and returns the result.
It's one of the ways to get to a dynamic lot size, if the account grows, lotsize is going to increase, and if it shrinks, lotsize will also lower.
Like an automatic gearbox.
Leverage is set by the broker. You can eventually request them to change it.
See also here.