This will be the final post of the series, that I had originally set out to write, and is about how Risk and Margin are controlled in the Expert Advisor that I shared here before.
In my EA, there are two parameters that control and limit, Risk and Margin, when orders are placed, namely “dblRiskMaximum” and “dblMarginMaximum”, with default values of 1.0 and 5.0 (percentage) respectively.
When an Order is placed, the volume to be used is the lesser of the two calculated limits. I will describe these two calculations using as an example, some of the reference data supplied by “Grock”, namely an Account balance of $372 USD with a Leverage of 1:50, trading GBP/USD. Let us also assume that the opening price of an order is 1.6165 and that the Stop-Loss is 5 pips.
[ul]
[li]First off, in my EA the Balance used for all calculations is the Minimum value of the Account Balance, Equity and Free Margin. However, assuming that there are no other orders open, these three should all have the same value. We will thus be using a value of $372 USD as per the example.
[/li]
[li]“dblRiskMaximum = 1.0”
[/li]Let us first look at the Risk calculation based on the Stop-Loss of 5 pips. Since the default value for this limit is 1.0 (%), then the risk is $3.72 USD. The Pip Value of the GBP/USD is $10.00 per standard lot, and so for a Stop-Loss of 5 pips, the risk would be $50.00 per standard lot. Our limiting volume is thus $3.72 / $50.00 = 0.0744. However, assuming that the minimum lot interval is 0.01, our calculated volume is thus 0.07 (working backwards, this is a total of 0.07 * $50.00 = $3.50 risk, representing approximately 0.94% of the Balance).
[li]“dblMarginMaximum = 5.0”
[/li]Now let us first look at the Margin calculation based on the Leverage of 1:50. In our previous post we have already calculated part of this information, specifically that the margin for these example values, is $32.33 per micro-lot or $3233.00 per standard lot. However, since we have set a limit of 5.0 for this parameter, this means that we want to limit our Margin on the order to no more than 5.0% of $372, namely $18.60 USD. So our maximum volume based on Margin is $18.60 / $3233.00 = 0.00575. This is obviously less than the minimum lot size, so we will have to use a volume of 0.01 instead (working backwards, this is a margin of $32.33, representing approximately 8.69% of the Balance).
[li]”The lesser of the two evils.”
[/li]The final volume used for opening the order is thus the smaller of the two calculations, specifically 0.01 lots. This would make our risk 0.01 * $50 = $0.50 for the 5 pip Stop-Loss, which represents 0.13% Risk of our balance when we originally wanted 1%.
[/ul]
NB! Obviously these two parameters are there to limit your risk and margin and thus protect your account from being wiped out. However, that does not mean that the EA will not run with higher risk or margin. [B]If you don’t want the margin protection, then just set the “dblMarginMaximum” to the value that pleases you, such as 100.0 (%)[/B], or if your broker allows for more, then feel free to set it higher, for example 120%. Obviously, I think that would be a foolish, but that is your choice to make and you are free to adjust the parameters as you see fit.
Also, please remember that even though you have set the Risk Limit, there can be slippage when an order hits a stop-loss, so that the resulting loss can be greater than the anticipated risk. During high volatility this can result in much higher loss than anticipated. So if you have a small balance and you have allowed for greater allowable margin, then the total value of the [B]potential loss plus margin could be greater than the account balance, causing your account to be stopped out and cleared completely[/B]. Hence, the need to limit your risk and margin and prevent wiping out your account.
Regards,
Carnino