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

 
ir0407:
Well... Seems to be a simple question and you start a polemic... :) I understand that everyone here is smart and a genius in their own way. But...
I've got a screenshot of MT5 or created a topic in the section that is not for MT4. I didn't come here to surprise 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 about 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 it. What I need is the name of constant(or its numeric value), which I can use in SymbolInfoDouble() query to get the value I need from the terminal. That's it! :)

Come on, come on ))))

Your question was clear from the beginning.

But margin is an interesting topic and, as you can see, the question is controversial.

 
Alexey Viktorov:

I can't understand why it's not working for you. Here you have 3 orders open and the margin is 100 per cent in line with the calculations



What calculations? Maybe I'm looking bad, but I don't see any comparisons in your screenshot.

And then, the question was also how to calculate the margin purely on gold without the "margin percentage" value, taking into account all the open orders on it...

And yes... taking into account hedged positions of course.

 
Alexey Viktorov:
In that case, the answer is unequivocal. I CAN'T!!!
Well, then I'll answer with a Stanislavsky quote: "I don't believe it!

Alexey Viktorov:

And no one will do that. It's a strange approach, though. I need it and you developers do it for me. Simply because I want them to.

Well the terminal knows this value... It knows and displays it in the "Contract Specification"... Do you really think that the terminal inside itself calculates and displays this value in the table? This is the base value! And it is used by the terminal to further calculate the correct margin for specific character types.

And why is this approach strange to you? Do you get all the other values from the "Contract Specification" by "calculation" too? By indirect or experimental data? :)

Alexey Viktorov: I sincerely tried to help... But alas, no luck...

Thank you, of course, but you took my theme in an unnecessary direction.

 
K-2SO:


What calculations? Maybe I'm not looking closely, but I don't see any comparison in your screenshot.

And then, the question was also how to calculate the margin purely on gold without the "margin percentage" value, taking into account all the open orders on it...

And yes... including hedged positions of course.

How to calculate the "margin percentage" has already been explained, chewed up and put in your mouth. All that's left to swallow... It's up to you.

You can use the hedged positions.

MarketInfo(_Symbol, MODE_MARGINHEDGED);
It's the amount returned, not the %% of collateral. Calculating the %% is not difficult at all.
 
Alexey Viktorov:

How to calculate the "margin percentage" has already been told, chewed up and put in your mouth. All that's left to swallow... That's up to you.

With the hedged positions taken into account, use

the amount returned, not the %% of the collateral. Calculating the %% is not difficult at all.

Get out of my way. I have shown you and tried to prove that when calculating collateral on all open positions for gold MARGINREQUIRED is useless. I may not be able to swallow something, but you seem unwilling to even chew.
 
ir0407:
Well, then I'll quote Stanislavsky: "I don't believe it!"

Well the terminal knows this value... It knows and displays it in the Contract Specification... And do you really think that the terminal is twisting in its calculations just to get this value and show it to us in the spreadsheet? This is the base value! And it is used by the terminal to further calculate the correct margin for specific character types.

And why is this approach strange to you? Do you get all the other values from the "Contract Specification" by "calculation" too? By indirect or experimental data? :)

Thank you, of course, but you've taken my topic in an unnecessary direction.

The terminal knows a lot of things and won't tell anyone. For example, I once tried to determine which order was closed by which counter. It fits into the commentary, but you can only get it from there... Where is the logic? Well, we don't have what we need and won't have it. We have to write our own calculations. Luckily they're not that complicated. And by the way, the margin currency should also be calculated and corrected in accordance with the exchange rate at the time of opening the order. And there is no CopyTicks in mql4. Therefore, we conclude that regardless of how you calculate the margin percentage, there will still be one more unknown, and there will anyway be inaccuracy in calculations.
 
Alexey Viktorov:
The terminal knows many things and does not tell anyone about it. For example, I tried to determine which order was closed by which counter. It all fits in the comment but it is the only way to get it... Where is the logic? I don't have it and it won't be.

Gods do not burn pots. Coders from meta-quotes are also human and can make mistakes or forget to do something. For example, to enter some values into the help. So now I will try to enter through the "backdoor" and I will report on the results a bit later.

Alexey Viktorov:
Hence the conclusion: Regardless of how you get the percentage of margin, there will be one more unknown and there will be inaccuracy in calculations.

I want to avoid these inaccuracies. And with as little blood as possible. :)

 
K-2SO:

Get away with it. I have shown you and tried to prove to you that when calculating collateral for all open positions for gold MARGINREQUIRED is useless. I may not be able to swallow something, but you seem unwilling to even chew.
Dear one, try reading this knowledge. I think it might help you. :)
 
K-2SO:

Get away with it. I have shown you and tried to prove that MARGINREQUIRED is useless when calculating collateral for all open positions for gold. I may not be able to swallow something, but you seem unwilling to even chew.

Look, I'm amazed at statements like that.

Here's the code.

  Comment("", MarketInfo(_Symbol, MODE_MARGINREQUIRED), "\n"
        , "", MarketInfo(_Symbol, MODE_MARGINHEDGED), "\n"
         );

here's the readings. 842.13 for current. and 50 for hedged positions.


Here's the Excell table with formulas and prices from the snapshot in the previous post. Explore...


The difference of 3 kopecks due to lack of EURUSD exchange rate at the moment of position opening for gold and this bullshit in the second line... What else is there to explain?

 
ir0407:
Dear Sir, try to read this knowledge. I think it will help you. :)


I have, it doesn't help, I need more specifics!

First calculate the margin percentage from MARGINREQUIRED and then apply it when calculating the margin of an already placed order?

So far I can only see it that way... With all the inaccuracies of course.

Reason: