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

 
K-2SO:

Where did you get that conclusion from?^ ^


The way margin is calculated for XAUUSD, also Forex there profit is futures, not what we are trying to calculate.

1. Be careful. So as not to bother you to go to the right page I will pull part of the table here.

SYMBOL_TRADE_CALC_MODE

Mode of contract value calculation

ENUM_SYMBOL_CALC_MODE


ENUM_SYMBOL_CALC_MODE

Identifier

Description

Formula

SYMBOL_CALC_MODE_FOREX

Forex mode - profit and margin calculation for Forex

Margin:Lots*Contract_Size/Leverage

Profit: (close_price-open_price)*Contract_Size*Lots

SYMBOL_CALC_MODE_FUTURES

Futures mode - calculate margin and profit for futures

Margin: Lots *InitialMargin*Percentage/100

Profit: (close_price-open_price)*TickPrice/TickSize*Lots

SYMBOL_CALC_MODE_CFD

CFD mode - calculation of margin and profit for CFD

Margin: Lots *ContractSize*MarketPrice*Percentage/100

Profit: (close_price-open_price)*Contract_Size*Lots


2. Don't tamper with the screenshots.


Where SYMBOL_CALC_MODE Forex or CFD is counting correctly.

3. I won't rewrite the script anymore. All I wanted to understand from this thread, I already understood. Thanks to the author of the theme.

 

Alexey Viktorov:

.................Everything I wanted to understand from this thread I have already understood. Thanks to the author of this thread.

Alexey, I am amazed at your persistence. The topic is really 100% covered. It was a pleasure to read and follow the thread.

Well done!

Write an article about margin, if it's not too much trouble.

Good luck to you!

 
Alexey Viktorov:

1. be more careful. To save you the trouble of going to the right page I will pull part of the table here.

2. Do not substitute screenshots

Where SYMBOL_CALC_MODE Forex or CFD is counting correctly.



I am just more confused again. What does this have to do with calculating the value of the contract when we're calculating the margin? And where did I change the screenshots if I only added new ones? I also mentioned XAUUSD, but I was too lazy to add screenshots.
 
Renat Akhtyamov:

Alexei, I'm amazed at your persistence. The subject is really 100% covered. I`ve been reading it with great pleasure and following the branch.

Well done!

Write an article on margin, if you don't mind.

Good luck to you!

Thank you for your kind words, but writing is not my craft. Besides, mql4 developers are not very interested in articles about mql4, it seems to me. In mql5, everything or almost everything is available in standard functions.

If you have the desire and ability, go ahead and write, I don't mind. If there will be references to me, thank you, there won't be, well, it's not really necessary...

 
Alexey Viktorov:

Thank you for your kind words, but writing is not my craft. And besides, mql4 developers are not very interested in articles about mql4, it seems to me. In mql5, everything or almost everything is available in standard functions.

If you have the desire and ability, go ahead and write, I don't mind. If there will be references to me, thank you, there won't be, well, I don't really need them...

Somehow, yes, it's better to keep it simple - question/answer.
 
K-2SO:

I'm just more confused again. What does this have to do with calculating the value of the contract when we are calculating the margin? And where did I change the screenshots if I only added new ones? And I also mentioned XAUUSD, I was just too lazy to add screens hots.

Yes, even though the formulas were originally taken from the table depending on how the contract value was calculated.

If you were too lazy to do that, you don't need to mention it. Programmers often perceive information just like a computer does - what it sees is what it processes. How can you understand it if you're talking about gold and you're attaching EURUSD to a screenshot...

 
Renat Akhtyamov:
Somehow, yes, it's better to keep it simple - question/answer.
That's how I started, but then I got sucked in like a swamp. Once upon a time, a long time ago, I wrote an information indicator for myself and for the sake of training. I wanted to insert margin for each order and then for the sum of orders of each symbol, but nothing worked then. And when I understood the essence of the margin percentage, I was eager to do what I was unable to do at that time... I don`t use that indicator now, but I`ve improved my knowledge... Thanks again to the author of the theme...
 
Alexey Viktorov:

Yes, the formulas were originally taken from a table depending on how the value of the contract was calculated.

If you are lazy, you do not need to mention it. Very often programmers perceive information absolutely like a computer, what it sees and processes. How can you understand if you're talking about gold, but you're attaching EURUSD...


Ok, let's leave gold aside to avoid confusion and leave aside the fact that you didn't answer why you calculated the margin using the contract calculation method and not the margin method as stated in the XAUUSD specification.

Specifically, here is again a screenshot of the EURUSD specification:

here is again a screenshot of an order placed on this symbol with a margin calculation (from the terminal):


Here it's all over the place, Forex type of calculation. By what formula can you get 1300 from the table you cited?

 
K-2SO:


Ok, let's leave gold out of the confusion and the fact that you got away with answering why you get your margin calculation method by the contract calculation method and not by the margin method as stated in the XAUUSD datasheet.

I wasn't even trying to go anywhere. Here's the answer.

Forum on trading, automated trading systems and testing trading strategies

How to get "Percentage of Margin" programmatically

Alexey Viktorov, 2017.06.08 18:45

Yes at that the formulas are originally taken from the table depending on how the contract value is calculated.

You can only add that this is the way the terminal developers have designed it.

K-2SO:


Here is a screenshot of EURUSD specification again:

here is again a screenshot of an order placed on this symbol with a margin calculation (from the terminal):


Here it's all over the place, Forex type of calculation. Using which formula can you get 1300 from the table you cited?

You have to correct the formulas separately for such a specific brokerage company. It is very simple, if all the normal margin currency is the base currency of the instrument, and this miracle is taken as a margin currency is strictly USD or the currency of the deposit, then it should be calculated taking into account.

1.We get margin in the currency of the deposit

double margin = MarketInfo(symbol, MODE_MARGINREQUIRED);

multiply it by the lot and that's it!!! All you have to do is to run it in the debugger and see what data is obtained. It's all shoved in here already.

This may be correct, but it is not for me to judge.

 
Alexey Viktorov:


You have to adjust the formulas separately for such a specific BC.

That's my point - there is no universal formula for calculating the deposit. So there may also be problems with calculating percentage.

Reason: