How do you calculate the margin? - page 2

 
Renat Akhtyamov:

no need to ask

we calculate by formulas

The formula I use to calculate the margin for an individual order is as follows:

OrderMargin = (OrderLots()*SymbolInfoDouble(_Symbol,SYMBOL_TRADE_CONTRACT_SIZE)*OrderOpenPrice())/AccountInfoInteger(ACCOUNT_LEVERAGE);

In the vast majority of cases, the sum of these values across all open orders equalsAccountInfoDouble(ACCOUNT_MARGIN).

However, in the case I described above, this formula gives an incorrect value. The reason is that the calculation uses a constant (for all orders) value of AccountInfoInteger(ACCOUNT_LEVERAGE). But in reality (in my case) it is not constant. My broker, according to the regulations, can decrease the leverage value tens of times for individual orders.

In other words, using this formula we will obtain the correct value of margin for 9 orders in the terminal (they have the standard leverage), while for the 10th and 11th orders- the incorrect one (the broker set higher leverage for them five minutes after opening).

Perhaps you, Renat, can give us another formula to correctly calculate the leverage for a single order?
Please note that it may be changed by the broker at any time after opening a position.

Just in case, this situationis not my fantasy. This is what was happening in my account tonight.

 
Janis Ozols:

The formula I use to calculate individual margin is as follows:

In the vast majority of cases, the sum of these values across all open orders equalsAccountInfoDouble(ACCOUNT_MARGIN).

However, in the case I described above, this formula gives an incorrect value. The reason is that the calculation uses a constant (for all orders) value of AccountInfoInteger(ACCOUNT_LEVERAGE). But in reality (in my case) it is not constant. My broker, according to the regulations, can decrease the leverage value tens of times for individual orders.

In other words, using this formula we will obtain the correct value of margin for 9 orders in the terminal (they have the standard leverage), while for the 10th and 11th orders- the incorrect one (the broker set higher leverage for them five minutes after opening).

Perhaps you, Renat, can give us another formula to correctly calculate the leverage for a single order?
Please note that it may be changed by the broker at any time after opening a position.

Just in case, this situationis not my fantasy. This is what happened in my account tonight.

It's only natural that it would be different.

What was the real leverage at the time of the opening?

i told you in black and white - note the real leverage in the comments or in magik when opening a deal.

you need to calculate the leverage instead of asking for it.

ps

leverage at the time of opening a deal will be the same as it is.

after the opening, nothing will change and it does not matter

VOL=MarketInfo("EURUSD",MODE_LOTSIZE);

LEVERAGE=NormalizeDouble(VOL/MarketInfo("USDCHF",MODE_MARGINREQUIRED),0);

in the market review obligatory presence of Euro and Franc

code for MQL4

If the leverage floats differently on different instruments and not at the same time, then we calculate according to the same principle
 
Renat Akhtyamov:

what was the real leverage at the time of opening?

At the time of the opening the real leverage was 1:1000. Right after I opened the SELL position with a volume of 0.10 EUR/USD at Bid=1.1800, the margin was 11.80 USD. At that time there were 9 other trades on the account, the margin of which was 86.20 USD. After opening the position, the margin was equal to 98.00 USD. Two minutes later the broker changed the leverage of the last open position to 1:33. Her margin was now 357.58 (instead of 11.80 when it was opened), and the total account marginwas 443.78 USD.

I'm trying to find a way (or formula) that will help me, going through the open positions in the terminal, to detect in time those for which the actual value of the margin exceeds repeatedly the calculated one (that was actual at the moment of position opening).

Renat Akhtyamov:

I wrote you in black and white - note the real leverage in the comments or in magic when opening a deal.

Please excuse me for being annoying, but I can not understand how the leverage saved at the time of opening a position can help me in this situation?

 
Janis Ozols:

At the time of opening, the real leverage was 1:1000. The margin for the SELLposition opening with a volume of 0.10 on EUR/USD at Bid = 1.1800 immediately after opening was 11.80 USD. At that time there were 9 other trades on the account, the margin of which was 86.20 USD. After opening the position, the margin was equal to 98.00 USD. Two minutes later the broker changed the leverage of the last open position to 1:33. Her margin was now 357.58 (instead of 11.80 when it was opened), and the total account margin was 443.78 USD.

I'm trying to find a way (or formula) that will help me, going through the open positions in the terminal, to detect in time those for which the actual value of the margin exceeds repeatedly the calculated one (the one that was actual at the moment of position opening).

Please forgive me for being annoying, but I can not understand, how the leverage, that was saved at the opening of a position, can help me in this situation?

You may only close part of a position, because almost all brokerage companies now have netting.

in this case. the margin of the open position will change

You have already closed your positions within 2 minutes?

 
Renat Akhtyamov:

nothing will change after the opening.

That's the tricky part! The leverage for a single order in my case was changedAFTERthe position was opened. And not immediately, but after some time. My broker's support worker confirmed it and I was able to reproduce the situation on my account.

Renat Akhtyamov:

the way you describe it is quite possible only when you close a part of the loco, because almost all brokerage companies now netting.

You did not close your order within 2 minutes?

No, I didn't close any trades and didn't use lots. There were only one direction trades in the terminal. After opening another SELL position with 0.1 volume I saw Margin = 98.00 in the terminal for some time. After about 2 minutes this value was equal to 443.78, right in front of my eyes. At the same time not a single line has been added to the journal, no Expert Advisors have been added. Only one chart is open and there is only one symbol in the market review.

After closing the ill-fated trade with a small loss the account margin became 86.20 again.

 
Janis Ozols:

That's the tricky part! The leverage for a single order in my case was changedAFTER theposition was opened. And not immediately, but after some time. The broker's support specialist confirmed it and I was able to reproduce this situation in my account.

No, I did not close trades and did not use lots. There were only trades of one direction in the terminal. After opening another SELL position with the volume 0.1 I saw Margin = 98.00 in the terminal. After about 2 minutes this value was equal to 443.78, right in front of my eyes. At the same time not a single line has been added to the journal, no Expert Advisors have been added. One chart is open, one symbol in the market overview.

Print leverage, open time and margin

formula and code above

and deal with the DC, according to the log

I personally do not believe in these unsubstantiated fairy tales.
 
Renat Akhtyamov:

And deal with the DC, according to the log

I have dealt with DC. Their answer is very simple- read the rules, it all says there. And it is indeed written there that the company reserves the right to change the leverage for certain positions opened under certain conditions. After that I asked a clarifying question- can I get the actual leverage for the next position BEFORE opening it? Using queries MarketInfo(_Symbol,MODE_MARGINREQUIRED), AccountFreeMarginCheck() or others? The answeris NO , reduced leverage will be set AFTER opening a position, corresponding to the conditions from the regulations, based on the current market situation.

Renat Akhtyamov:
I do not believe in these unsupported fairy tales.

I am in no way trying to convince you of anything! Moreover, I am glad you have not encountered a similar situation. I have faced it myself for the first time in several years of working with this broker.

Summing up everything you told, am I right to understand that there is no native way to get by MQL4 means an actual (not calculated) margin for an open position in the terminal at any point of time, provided that this value hasn't been saved somewhere before?

 
Janis Ozols:

I have dealt with the DCs. Their answer is very simple- read the rules, it all says there. It does say that the company reserves the right to change the leverage for certain positions opened under certain conditions. After that I asked a clarifying question- can I get the actual leverage for the next position BEFORE opening it? Using queries MarketInfo(_Symbol,MODE_MARGINREQUIRED), AccountFreeMarginCheck() or others? The answer- NO , reduced leverage will be set AFTER opening a position, corresponding to the conditions from the regulations, based on the current market situation.

In no way am I trying to convince you of anything! Moreover, I am very glad that you have not encountered a similar situation. I have faced it myself for the first time in several years of working with this broker.

Summing up everything you said, am I right to understand that there is no native way to get by MQL4 means an actual (not calculated) margin for an open position in the terminal at any point of time, provided this value hasn't been saved somewhere before?

because i read the rules BEFORE and not AFTER

and if something does not suit me I do not work in such a place

 
Janis Ozols:

Summing up, am I right to understand that there is no native way to get by MQL4 means an actual (not calculated) deposit for an open position in the terminal at any point of time, provided this value has not been saved somewhere earlier?

Yes, that's right.

Only the leverage most likely changes not for a single deal, but for an instrument as a whole, but it doesn't change the matter.

I'll add an alert to my informer for this case...

 

The AccountLeverage() function hints that the account's leverage changes. Individual symbols may have different leverage than the account, depending on the exotics of the symbol (Fx Minors, Fx Exotics, Fx Rub) and the volume of the position. In any case, you need to read the regulations and contract specifications.

At interesting times any trading operation changes the leverage of the account. For the leverage to change, you have to make a trade. I once deleted a pending order that was forgotten and unpromising. So to speak, I cleaned up. As a result, the account leverage was reduced from 500 to 100.

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Типы торговых операций
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Типы торговых операций
  • www.mql5.com
Торговля осуществляется посредством отправки с помощью функции OrderSend() приказов на открытие позиций, а также приказов на установку, модификацию и удаление отложенных ордеров. Каждый торговый приказ содержит указание на тип запрашиваемой торговой операции. Торговые операции описаны в перечислении ENUM_TRADE_REQUEST_ACTIONS...
Reason: