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

 
K-2SO:


Ok, let's leave gold aside to avoid confusion and leave aside the question why you calculate the margin using the contract calculation method and not the margin method as stated in the XAUUSD specification.

Here is a screenshot of the EURUSD specs again:

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


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

By this one:

ID

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


K-2SO:

there is no universal formula for calculating margin.

Who and where said that it must be universal? The table was given to you to let you know how to perform calculations for different instruments. This table contains everything you need to write a universal function that will calculate anything and everything.

K-2SO:

Consequently, there may also be problems with calculations.

Only if the maths textbook has been bitten before it has been read and absorbed.

 
K-2SO:

That's my point - there is no universal formula for calculating the deposit. Consequently, there may be problems in calculating the percentage.

It seems that not only have I smoked arithmetic before, but... I'm speechless.

After all, all this can be solved by simple additions/changes to conditions. In my first version, I stupidly inserted "USD" when I had to put

     string accountCurrency = AccountCurrency();

and corrected two lines accordingly.

     double price = accountCurrency == symbolCurencyMargin ? 1 : type%2 == OP_BUY ? bid : ask;
     double orderOpenPrice = accountCurrency == symbolCurencyMargin ? 1 : OrderOpenPrice();

That's all... If you want the variant with the possibility of determining the margin for futures, make a personal request here and send me the link here or in private. I will do for minimal price.

 
ir0407:

By this one:

ID

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



Well, try to calculate it, you don't even need to write a code, the specification and a screenshot of the terminal calculations are right in front of you, calculate for yourself :D

The leverage is 100, if anything

ir0407:


And who said that it should be universal? The chart was given to you to let you know how to perform calculations for different instruments. This table has everything you need to write a universal function that will calculate anything and everything.

That's only if the maths book was chewed up before it was read and assimilated.

I'm a real programmer too - I see the last post (picture), react to the last post... Context is the key. I meant a universal formula for an already defined type of calculation. If it is FOREX, then this type of calculation should be the same for all brokers.
 
Alexey Viktorov:

It seems that not only have you smoked arithmetic before, but also ... I'm speechless.

After all, this is all solved by simple additions/changes to the conditions. In my first version, I stupidly inserted "USD" when I had to put

and corrected two lines accordingly.

That's all... If you need a variant with the ability to determine the margin on futures, make a personal request here and throw the link here or in private. I will do for the minimum price.


I don't know what you're smoking there, but what doesthe name of the currency of the current account have to do with it? And I don't want to order anything from you - I don't need it for nothing when the calculations are wrong. I want to understand it, if I am wrong, poke me in it, and so far I have not seen anything besides the theory that anything is possible in your latest posts. I gave you a concrete example, the currency of the deposit is the same as the currency of the margin, all the calculations are exclusively in quid. So get me that 1300 in the standard Forex calculation method described in the table.

If you don't want to continue the discussion, you have an absolute right, but I don't have to silently look into your mouth and nod when I don't see the practical implementation of your words ... or we're talking about different things.

 
K-2SO:


I don't know what you're smoking there, but what doesthe current account currency have to do with it? And I don't want to order anything from you - no need for nothing when the calculations are wrong. I want to understand it, if I am wrong, poke me in it, and so far I have not seen anything besides the theory that anything is possible in your latest posts. I gave you a concrete example, the currency of the deposit is the same as the currency of the margin, all the calculations are exclusively in quid. So get me that 1300 in the standard Forex calculation method described in the table.

If you don't want to discuss it further, that's your absolute right, but I don't have to silently look you in the mouth and assent when I don't see the practical implementation of your words... or we're talking about different things altogether.

You're a hard man. Well, everything has been said and more than once. How else can I explain it? Here's what the script prints with the fixes I gave in the last post

2017.06.09 14:05:09.875 Script test EURUSD,H4: removed
2017.06.09 14:05:09.874 test EURUSD,H4: uninit reason 0
2017.06.09 14:05:09.874 test EURUSD,H4: ******** AccountMargin = 1300.00 USD
2017.06.09 14:05:09.874 test EURUSD,H4: ******** Процент маржи 130 Маржа ордера EURUSD 1.0 = 1300.0
2017.06.09 14:05:09.874 test EURUSD,H4: initialized
2017.06.09 14:05:09.857 Script Test\test EURUSD,H4: loaded successfully

And the same script on Robo's account.

2017.06.09 14:11:51.192 Script test USDJPY.e,M15: removed
2017.06.09 14:11:51.191 test USDJPY.e,M15: uninit reason 0
2017.06.09 14:11:51.191 test USDJPY.e,M15: ******** AccountMargin = 2166.67 USD
2017.06.09 14:11:51.191 test USDJPY.e,M15: ******** Процент маржи 200 Маржа ордера XAUUSD.e 1.0 = 840.4333333333334
2017.06.09 14:11:51.191 test USDJPY.e,M15: ******** Процент маржи 1 Маржа ордера WTI 1.0 = 484.9
2017.06.09 14:11:51.191 test USDJPY.e,M15: ******** Процент маржи 100 Маржа ордера USDJPY.e 1.0 = 333.3333333333333
2017.06.09 14:11:51.191 test USDJPY.e,M15: ******** Процент маржи 1 Маржа ордера BRENT 1.0 = 508.0
2017.06.09 14:11:51.190 test USDJPY.e,M15: initialized
2017.06.09 14:11:51.179 Script Test\test USDJPY.e,M15: loaded successfully


 
K-2SO:

Well, try to calculate by it, you don't even need to write a code, the specification and a screen of terminal calculation are right in front of you, calculate for yourself :D

My calculator calculation took 30 seconds and matched the number on your screen.)
K-2SO:

The leverage is 100, if anything.

You can see it without your addition.


The formula Lots*Contract_Size/Leverage is basic and it is used to calculate the margin for all Forex instruments.

And then there are peculiarities of each particular kitchen (i.e. brokerage companies).

1. Margin currency may be different from the currency of the deposit. Consequently, the result obtained by the basic formula to be converted to the currency of the deposit.

2. Kitchen can apply discounts/surcharges that are reflected in your screenshot in the column "Margin Percentage". If the number in this column is different from 100% you have to take this into account in your calculation.


On the first point, you have a deposit currency USD - then do not recalculate. But for the second item, you have a "margin percentage" = 130% ... Does this ring any bells? Margin is 1300 quid and "Percentage of Margin" is 130%. Are you so blind that you can't see that?

 
ir0407:

The kitchen can apply the discounts/surcharges that are shown in your screenshot in the column "Percentage of margin". If the number in this column differs from 100%, you have to take it into account in your calculation.

For the first point, your deposit currency is USD, so you do not need to recalculate. But for the second item, you have "Margin Percentage" = 130%... Does this ring any bells? Margin is 1300 quid and "Percentage of Margin" is 130%. Are you so blind that you can't see that?


Exactly taking into account the percentage of margin (in the Forex calculation method) is what confused me, because it was the only way for me to get the result I was looking for. And indeed other (conventional) brokers, where the basic formula may not take into account the percentage of margin, it is equal to 100 - I also checked it a few days ago. I just wanted an independent confirmation of my conclusions... and it's also clear to me how to apply it to the general formula for calculating the margin for this type of deposit. All that's left to do is to finalise the universalisation (if it's really possible) of the margin percentage calculation - Alexey's posts are a help to me.
Reason: