First advice. If you have to calculate the available margin, you are trading WAY too heavy.
Here's the way I calculate it:
First, decide % of your account balance you're willing to risk. This is a personal decision, but in my not so humble opinion, anything above 5% is going to introduce you to the concept of a margin call sooner or later.
For example, if you have $5000 in your account and want to risk 2% of that on a trade, then you are putting $100 on the table. Now comes the fun part.
Based on value per pip and desired stop loss, you get to calculate your maximum position size.
For xxx/USD pairs, this is easy. It's $10 per pip if you are trading full lots. If you planned a 10 pip SL (don't forget you'll start out a few pips towards your SL because of spread), you could trade 1 full lot.
Of course, most trades use a larger SL. For a 20 pip SL on a USD pair where you are risking $100 on the trade, your position size would be 1/2 lot ($5 per pip). 25 pips would set your size to 0.4 lots. 100 pips would set you to 0.1 lots.
This article should help:
How to Manage Risk while Forex Trading
I hope this helps.