need help with margin call/stopout

 

Hi,

Given that:

AccountStopoutMode()=0,

AccountStopoutLevel()=100,

leverage=400,

maximum pips retracement which will cause stopout = 130 pips.

How do I calculate the lotsize?

Any idea would be appreciated.

Thanks.

 
You could use MarketInfo(Symbol(), MODE_TICKSIZE) and MODE_TICKVALUE
 
GumRai:
You could use MarketInfo(Symbol(), MODE_TICKSIZE) and MODE_TICKVALUE

Thanks, but I mean calculate the maximum lotsize, which will cause stopout, if 130 pips lost.
 

StopoutLevel =100 means you get stopped out when 100% of your balance is used up as margin and/or as losses, i.e. when Balance = margin + losses

Assuming you have only 1 order, and no other orders are open:

one_point = value of one point change for 1 lot.... often this is MODE_TICKVALUE

one_margin = margin size for one lot... this is MODE_MARGINREQUIRED

Lots = number of lots in the order

Balance = Lots * one_margin + Lots * 1300 * one_point

--> Balance = Lots * ( one_margin + 1300 * one_point )

--> Lots = Balance / ( one_margin + 1300 * one_point )

Note: I haven't checked this.. just maths.

PS of course, if your broker charges commission, you need to put that in the equation too, Also the 1300 points includes the spread

PPS apologies! I always think in points not pips, so I edit the post, 130 pips usually = 1300 points on 5 digits brokers

 
joshatt:

Thanks, but I mean calculate the maximum lotsize, which will cause stopout, if 130 pips lost.

Yes, you use
MarketInfo(Symbol(), MODE_TICKSIZE) and MODE_TICKVALUE

to calculate how much 1 tick is valued, usually multiply this by 10, (but in not all cases) to find 1 pip value for 1 lot.

Multiply by 130

You then know how much you would lose with a 130 pip loss for 1 lot.

Divide the amount that you can lose by this figure and you have your lotsize.

Of course make sure that it is a valid size using MODE_LOTSTEP and MODE_MINLOT

 
joshatt: maximum pips retracement which will cause stopout = 130 pips. How do I calculate the lotsize?
Your question assumes you will have only 1 open order (only one chart.) You must calculate free margin at the most adverse excursion (i.e. SL) for all orders. See my code.
 

Thanks, GumRai and alladir. Crystal clear! This puzzled me for a long time. Though I'll try to understand digits,etc., but the logic is very clear.

~cheers.

 

Yes, you use
MarketInfo(Symbol(), MODE_TICKSIZE) and MODE_TICKVALUE

to calculate how much 1 tick is valued, usually multiply this by 10, (but in not all cases) to find 1 pip value for 1 lot.

Multiply by 130

ticksize and tickvalue is in points not pips.
 
WHRoeder:
Your question assumes you will have only 1 open order (only one chart.) You must calculate free margin at the most adverse excursion (i.e. SL) for all orders. See my code.


You sure have done some thorough and perfect job. I'll try to understand and learn.

Thanks!

 
WHRoeder:
ticksize and tickvalue is in points not pips.


I realise that my post wasn't that well written, but neither ticksize or tickvalue are expressed in points.

Ticksize is the smallest possible move in the instrument.

Tickvalue is the monetary value of the smallest possible move (for 1 lot) expressed in the deposit currency.

 
GumRai: I realise that my post wasn't that well written, but neither ticksize or tickvalue are expressed in points.
That is why you use them as a ratio and multiply by the change in price. https://www.mql5.com/en/forum/143709