How to understand equity, balance and freemargin?

 
I see three functions: AccountEquity(), AccountBalance() and AccountFreeMargin(). How to understand the difference among the equity, balance and freemargin on my account? It's appreciated if you can help explain them one by one with their difference. Thanks.
 
please also help to understand credit.
 

Account balance is the balance not including the floating profit/loss from any open trades

Equity is the account balance plus or minus  the floating profit/loss from any open trades

Free margin is the equity minus the margin used for open trades. 

 
Thank you, GumRai. How to understand Credit? What the defference between credit with balance, quity?
 
jollydragon:
Thank you, GumRai. How to understand Credit? What the defference between credit with balance, quity?

Any AccountCredit() on the account isn't your money. In effect, it's the broker's money which they are letting you trade with.

It's most commonly used in relation to promotions where brokers are trying to get you to trade more. For a period of e.g. 3 months, they put a credit on your account which makes it possible for you to place larger trades, but you can't withdraw that money because it's a credit rather than a deposit, and isn't yours. The broker then removes the credit at the end of the promotion.

Another example is a trading competition where the prize is a "$5000 trading account", but where you can only withdraw any profits you make, i.e. you're not actually getting a prize of $5000. One way of setting that up in MT4 is to put in $5000 of AccountCredit() rather than deposit.

Reason: