How to get the "Percentage of Margin" programmatically - page 2

 
Alexey Viktorov:

Yeah, well... fantasy is everything... but why should people trying to help you fantasize about what you fantasize about? Anyway, that's not the question.

How do you get what you need from that formula?

The formula itself is Margin = Lots *ContractSize*MarketPrice*Percentage/100

Hence, Percentage = Margin/(Lots *ContractSize*MarketPrice/100)

It is not in the list of obsolete functions yet. So it produces the missing value to determine the percentage of margin.

Having received all the data for the current moment at the current price, we can easily recalculate the margin that was withheld at the order opening price.

If you need it for mql5, you should use

Norm.

The leverage will not affect the margin? Maybe we should add the coefficient: 100/leverage to the formula?

 
Renat Akhtyamov:

Norm.

Will the leverage have no effect on the margin? Maybe add a coefficient to the formula: 100/leverage ?

The leverage is generally outside of the basic formula Margin = (Lots*ContractSize*MarketPrice*Percentage)/Leverage, so I did not take it into account. For determining what the question is about, the leverage is like a cow's saddle. But further it may be required, but it doesn't concern the current question...

 
Alexey Viktorov:

The leverage is generally outside of the basic formula Margin = (Lots*ContractSize*MarketPrice*Percentage)/Leverage, so I did not take it into account. For determining what the question is about, the leverage is like a cow's saddle. But further it may be required, but that's beyond the scope of the current question...

The margin as a percentage may only be on something (e.g. deposit) with the minimum lot taken into account. The leverage is just "in for something".
 
Renat Akhtyamov:
A percentage margin can only be a percentage of something (e.g. a deposit), taking into account the minimum lot. The leverage is just "for something".
Renat, don't be in such a hurry. Read everything from the first post, what the question was about...
 
Alexey Viktorov:

Yeah, well... fantasy is everything... but why should people trying to help you fantasize about what you fantasize about? Anyway, that's not the question.

How do you get what you need from that formula?

The formula itself is Margin = Lots *ContractSize*MarketPrice*Percentage/100.

Hence, Percentage = Margin/(Lots *ContractSize*MarketPrice/100)

It is not in the list of obsolete functions yet. So it produces the missing value to determine the percentage of margin.

Having got all the data for the current moment at the current price, we can easily recalculate the margin that was withheld at the order opening price.

If you need it for mql5, you should use


Hello, I would like for example to calculate margin separately for gold (independently of other instruments). Can you tell me how to do it, if you do not know the percentage margin? Because in this case, we already have two unknowns: the margin itself and the margin percentage...
 
K-2SO:

Hello, I would for example like to calculate margin separately for gold (independently of other instruments). Can you tell me how to do it, if the margin percentage is unknown? Because in this case we already have two unknowns: both the margin itself and the margin percentage...

My answer is all there is to calculate everything you need.

MarketInfo(_Symbol, MODE_MARGINREQUIRED); // Размер свободных средств, необходимых для открытия 1 лота на покупку
However, this is not a margin amount taken at the time the order is opened, but it is the current margin at the current price. Only one unknown is left, i.e. the percentage margin that is not a percentage value and that is calculated using the formula. Then we are left with the price that does not correspond to the last one. Again, using the same formula, we calculate the margin for the corresponding price.

The error in the calculations may be a couple of pennies, but that's the cost of rounding.

MarketInfo - Получение рыночной информации - Справочник MQL4
MarketInfo - Получение рыночной информации - Справочник MQL4
  • docs.mql4.com
MarketInfo - Получение рыночной информации - Справочник MQL4
 
Yeah... Seems to be a simple question and you start a polemic... :) I understand that all are smart people and everyone is a genius in his own way. But...
Renat Akhtyamov:

If you want to use MT5, go to another section of the forum.

I've got a screenshot from MT5 or I've created a topic in the section that isn't for MT4.
Renat Akhtyamov:

You didn't surprise me with your common knowledge, or worse:

I did not come here to amaze you, but to get a simple answer to a simple question.
Alexey Viktorov:

Well, yes... I do not understand why people trying to help you should fantasize about what you have fantasized about.

I didn't ask anyone to fantasize about anything. You have got yourself into the thicket.
Alexey Viktorov:

How do you get what you need from that formula?

The formula itself is Margin = Lots *ContractSize*MarketPrice*Percentage/100

Hence, Percentage = Margin/(Lots *ContractSize*MarketPrice/100)

I know how to derive the right value from the formula myself. We're good at maths. The question was not how to calculate it, but how to get it from the terminal.

Alexey Viktorov:

If you need it for mql5 you should use

MQL5 again...

Let me rephrase my question... I don't need this value or a formula to calculate it. I want the name of constant(or its numeric value) that I can use in SymbolInfoDouble() query to get the value I need from the terminal. That's it! :)

 
ir0407:
Well... Seems to be a simple question and you start a polemic... I didn't take a screenshot from MT5 or created a topic in the MT4 section. I didn't come here to amaze you, but to get a simple answer to a simple question. How to take the right value out of the formula, I'm well aware of it. We're good at maths. The question was not how to calculate, but how to get it from the terminal.

MQL5 again...

Let me try to rephrase the question... I don't need to calculate this value, I don't need a formula to calculate this value. I need a constant name(or a numeric value) which I can use in SymbolInfoDouble() query to get the value I need from the terminal. That's it! :)

In that case, the answer is unequivocal.

NOTHING!!!

And no one is going to do it. It's a strange approach, though. I want it, and you developers do it for me. Just because I want to. I sincerely tried to help... but alas, no luck...

 
Alexey Viktorov:

My answer has everything to calculate everything you need.

But it's not the margin taken at the moment of order opening; it's the margin at the present time, at the current price. Only one unknown is left, i.e. the percentage margin that is not a percentage value and that is calculated using the formula. Then we are left with the price that does not correspond to the last one. Again, using the same formula, we calculate the margin for the corresponding price.

The calculation error may be a couple of kopecks but it is the rounding error.

You can do a simple experiment, comparing the value of MARGINREQUIRED and placing real orders of one lot size on different instruments. And then it will become clear that MARGINREQUIRED is lying not only for sales, but also for cross rates.

And, secondly, when calculating the total margin for the instrument for all of its orders (gold, in our case), it is the order open prices that must be taken into account. The MARGINREQUIRED value does not give us anything at all here.

 
K-2SO:

A simple experiment can be conducted comparing the MARGINREQUIRED value and placing real orders of one lot size on different instruments. And then it will become clear that MARGINREQUIRED lies not only in selling, but also in cross-rates.

And, secondly, when calculating the total margin for the instrument for all of its orders (gold, in our case), it is the order open prices that must be taken into account. The MARGINREQUIRED value does not give me anything at all here.

I cannot understand why it does not work. Here we have 3 orders open and the margin value corresponds to all the calculations by 100%.


Reason: