How can you avoid this unanticipated surprise? Margin calls can be effectively avoided by carefully monitoring your account balance on a regular basis, and by using stop-loss orders on every position to minimise the risk. Another smart action to consider is to implement risk management within your trading. By managing your the potential risks effectively, you will be more aware of them, and you should also be able to anticipate them and potentially avoid them altogether.
Now that we have discussed the longer term plan I want to present some of the changes I have made to the code since diary entry #2. In particular, I want to describe how I modified the code to handle the Decimal data-type instead of using floating point storage. This is an extremely important change as floating point representations are a substantial source of long-term error in portfolio and order management systems.
For securities, the definition of margin includes three important concepts: the Margin Loan, the Margin Deposit and the Margin Requirement. The Margin Loan is the amount of money that an investor borrows from his broker to buy securities. The Margin Deposit is the amount of equity contributed by the investor toward the purchase of securities in a margin account. The Margin Requirement is the minimum amount that a customer must deposit and it is commonly expressed as a percent of the current market value. The Margin Deposit can be greater than or equal to the Margin Requirement. We can express this as an equation:

So, for an investor who wants to trade $100,000, a 1% margin would mean that $1,000 needs to be deposited into the account. The remaining 99% is provided by the broker. No interest is paid directly on this borrowed amount, but if the investor does not close their position before the delivery date, it will have to be rolled over. In that case, interest may be charged depending on the investor's position (long or short) and the short-term interest rates of the underlying currencies.
These articles, on the other hand, discuss currency trading as buying and selling currency on the foreign exchange (or "Forex") market with the intent to make money, often called "speculative forex trading". XE does not offer speculative forex trading, nor do we recommend any firms that offer this service. These articles are provided for general information only.
Trading on margin refers to trading on money borrowed from your broker in order to substantially increase your market exposure. When opening a margin trade, your broker lends you a certain sum of money depending on the leverage ratio used, and allocates a small portion of your trading account as the collateral, or margin for that trade. The remaining funds in your trading account will act as your free margin, which can be used to withstand negative price fluctuations from your existing leveraged positions, or to open new leveraged trades. The relation between your free margin and other important elements of your trading account, such as your balance and equity, will be explained later. For now, it’s important to understand the meaning of margin in Forex.