You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Sorry, it is AccountInfoInteger(ACCOUNT_LEVERAGE) in MT5.
Leverage has nothing to do in this calculation, unless you use money management that takes into account free margin, which is not the case here.
wiptheman,
Did you solved your problem with lots size ?
I must apologize for very late reply.
Actually, I already wrote the answer but when I re-read my own answer ... well I don't understand it :). So I guess I just have to re-write my answer all over again.
Here we go :
1. To find out how much money (read :margin) needed to open position at given open price and at a given lot size, we use OrderCalcMargin. When we use OrderCalcMargin, there's no need to also calculate leverage, or lot standard per unit, into our margin calculation, because everything already calculated inside OrderCalcMargin.
2. To find out how much profit (or loss) we have from the open price (denoted in account currency), we use calculation that involve four components, they are : lot size, number of Point from open price, and PositionInfoDouble's SYMBOL_TRADE_TICK_VALUE and SYMBOL_TRADE_TICK_SIZE. Here's the calculation :
code # 1 for profit (or loss) of current position in account currency
Now, let's have a problem :).
Let's say we have account in US Dollar for $ 10,000.- . Question is how much lot size to open if we want only spend US$ 400 to open sell GBPJPY including for its losses at 300 Points (30 pips).
As you can see, my account currency is US Dollar (USD) and I want to open sell a position for symbol that have UK Pound as base currency (GBP) and Japanese Yen as quote currency (JPY), and we want to spend only $ 400 for both open sell position and for its losses as well.
First thing we do is, to calculate how much money (margin) needed if we want to open sell just one lot.
Well currently GBPJPY bid is at 140.825. Since my leverage is 1:500, the cost (money needed) to open sell 1 lot GPBJPY will be US$ 301.12. This cost will change with every single tick of bid price of GBPJPY and will be different if we using different leverage and different standard lot per unit.
code # 2 for how much margin need for 1 lot sell GBPJPY at 140.825
Second thing we do is calculate how much our losses is - in our account currency (US $) - if we set stop loss for 300 points or 30 pips.
Remember, we still have to use one lot size as our standard calculation. Another thing to remember, whether we using fractional pips broker or not, we have to use point to calculate this and not pips. So if we set stop loss at 47 pips and we are not using fractional pips broker, we should use 47 points instead 470 points for calculation.
The result from the code below show that if we have our 300 points stop loss executed with 1 lot size in GBPJPY, we will loss our money about US$ 320.70126677
code # 3 for how many losses in our account currency if we set stop loss (read : if we loss) 300 points
Now that we know the money needed to open sell 1 lot size of GBPJPY and its losses at 300 point, then we calculate how much lot size have to open if we only want to spend US$ 400 open sell GBPJPY with 300 point stop loss.
code # 4 how much lot size to open if we want only spend US$ 400 to open sell GBPJPY including for its losses at 300 Points (30 pips)
The result of code above is that we have raw_lot of 0.64327166.
Surely we can not send this 0.64327166 lot size to broker, because we must check and follow broker requirement to send lot, by using SymbolInfoDouble's SYMBOL_VOLUME_MIN, SYMBOL_VOLUME_MAX, SYMBOL_VOLUME_STEP, and SYMBOL_VOLUME_LIMIT.
I write about that later, and I also will explain why we should NOT use conversion function NormalizeDouble at all when sending any order to broker.
NormalizeDouble is the solution! for... I fell into that pit so many times...
Just thought I would also share my volume function that only has two input parameters; the trade symbol name and margin to be invested. The input trade margin is in USD.