EarnForex / PositionSizer

Calculate your position size based on the risk and account size and execute your trades with this free MetaTrader expert advisor.

Home Page:https://www.earnforex.com/metatrader-expert-advisors/Position-Sizer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in margin calculation for XAUUSD

maccieddu opened this issue · comments

Hi, i have noticed that in the margin tab the calculation for the specific contract is incorrect...
On the specific contract the margin is calculated like this:
(trade size * contract size * price / leverage) * margine rate
On this particulare broker the leverage is 4 and the margin rate is 3 so the calculation is:
(0.07 * 100 * 1900.00 / 4) * 3 = 9975$
But the position sizer give me the value of
(0.07 * 100 * 1900.00 / 4) * 2.5 = 8312.5$ that is the value calculated with margin rate maintenace 2.5

Is it possible to add a textbox were insert a custom margin rate alongside the custom leverege that is in place now or let the user chose the margin rate initial or maintenace?

margin
image

Thank you for letting me know. I will consider adding both calculations.

Hello! Could you please let me know which broker is that, so I could test?

Hello, it's a prop firm not a broker...

Could you please let me know which one? I would ask them for a demo account to test this?

Yes sure, the prop is the5ers.

Hope you got the demo for testing this fix...

Sorry, they refused to provide a demo account. I couldn't find any other broker that have different but non-zero initial and maintenance margin. Besides, I've been busy with another project.

I will soon prepare a fix for this and will send you a beta, so you could see if it works in your account.

Ok, i'm very sad that they not provide you a demo to improve a strument like this... i'm looking for the beta to test your proposed fix and i will tell you if its work. I know its very hard to fix thing without testing in first person

Hello @maccieddu ! Was this on a netting account or on a hedging one?

Hello! Is a hedging one

Position Sizer.zip
Please try the attached version when you have time and let me know how it works in your account.

I'm trying it right now, but i dont see changes in the calculation. I have to enable something? For your info i have downloaded the indicator of max lotage from the prop: https://the5ers.com/downloads/ and the max lot limit is different from what is calculated from position sizer.
image

In theory the formula would be this (correct me if i'm wrong):
(Volume in lots * Contract size * Open market price / Leverage) * Margin Rate? for example:
(0.42 * 100 * 1923.00$ / 10) * 3 = 24229.8 <---- (3 is the initial margin) the account is of 25k

with position size calculator that propose me 0.49 lot max the calculation is this:
(0.49 * 100 * 1923.00$ / 10) * 3 = 28268.1 <---- (3 is the initial margin)

i think the problem is the margin rate used in the formula

Maybe this lines of code are where the margin is calculated and they use maintenace_margin_rate instead of initial_margin_rate
image

Attached a wrong file in my previous (deleted message). Please use the one attached here.
Position Sizer.zip

It seems to be going much better now.
image

However, I continue to notice very small differences, in the other pairs, between the values calculated with the tool provided by the prop and with the values calculated by the position sizer, at this point I believe that each instrument (forex, indices, metals) has its own formula for the calculation of the required margin. But the situation has improved now
image

Make sure you are attaching the version that I uploaded in this thread. It should say "ver. 3.062" in the header. The last four screenshots show "3.06".

As for the remaining difference (0.41 vs 0.42), it might be attributed to rounding down vs rounding up. But if you notice a bigger difference, please let me know.

Is the initial margin on SP500 and EURUSD also larger than the maintenance margin?

Thank you! Is your account in USD?

Yes sir.

The Position Sizer uses Free Margin for max position size calculation. Perhaps, you have open trades and the firm's calculator is using balance or equity for its calculation? Could you please check?

I send you screenshot with no trade open, so equity is equal to balance

Perhaps the problem is that every asset have is own margin calculation? https://www.metatrader5.com/en/terminal/help/trading_advanced/margin_forex
If you read in the last screen shot on the row: calculation, one have type forex and one CFD leverage
p.s. im sorry for my bad english, hope is understable

Do you know your account's stop-out level? It's another factor considered by the Position Sizer when calculating the Max Position Size by Margin.

Yes, it's different for each broker. The attached script prints your account's stop-out mode and level when you run it. Could you please let me know what it says?
PrintStopOut.zip

And your current free margin is?

The account start size is 25000$ now is 24387.90$

I think that explains the difference between the two values for PS and the firm's indicator:
24387.9 / 23750 = 2.30 / 2.24 for example

Ah ok now sound good, so the position sizer is more reliable of firm's indicator if i understand good?

I don't know. The Max Position Size feature in the Position Sizer is designed so that if you take that trade, you will be as close to the stop-out as possible without actually getting stopped out (OK, you'll probably get stopped out anyway due to the spread, but still...).

It looks like their calculator, doesn't consider the stop-out level at all. So, taking a trade size that it offers will likely result in an immediate stop-out regardless the current spread or anything like that.

I think you are right, therefore i continue to use position sizer as only reference to risk.
So you think that now implement the double visualization of maintenace and initial margin is worth, maybe the initial margin only is the best option for the broker that provide two different margin rate?

For now, I think, that when both are given, the best option is to use the maintenance margin only for the Future margin calculation, and the initial margin for everything else. I don't think it's necessary to display the margin rates on the panel for now.

Fixed in 3.07.