EarnForex / PositionSizer

Calculate your position size based on the risk and account size and execute your trades with this free MetaTrader expert advisor.
https://www.earnforex.com/metatrader-expert-advisors/Position-Sizer/
Apache License 2.0
406 stars 158 forks source link

Invalid leverage/margin calculation #44

Closed imphocused closed 2 years ago

imphocused commented 2 years ago

Screen Shot 2022-06-25 at 10 11 04 PM

Is it possible to adjust how the leverage is calculated? On this broker (Dominion Markets, MT5) the calculations for crypto are off.

Screen Shot 2022-06-25 at 10 18 24 PM

EarnForex commented 2 years ago

Hello imphocused!

The problem here is that the symbol's calculation mode is reported as SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE, while in reality it looks more like SYMBOL_CALC_MODE_CFD is used.

In SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE, margin is calculated as Lots Contract_Size Margin_Rate. The price of the symbol isn't taken into account or is taken care of by the Margin_Rate (reported by the broker's server).

In SYMBOL_CALC_MODE_CFD, margin is calculated as Lots ContractSize MarketPrice * Margin_Rate. This would yield a correct result here.

So, the broker should either fix the reported SYMBOL_TRADE_CALC_MODE or Margin_Rate on its server.

imphocused commented 2 years ago

Hello,

Thank you for taking a look. I appreciate the feedback. I've relayed this to the broker support team, and even with screenshots there is some confusion on what I was talking about, so they may not be able/willing to resolve.

In any case, to help me better understand, I may be confused about the specification calculation. You mentioned:

"In SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE, margin is calculated as Lots Contract_Size Margin_Rate. The price of the symbol isn't taken into account or is taken care of by the Margin_Rate (reported by the broker's server)."

On the MT5 page:

Forex: The margin for the Forex instruments is calculated by the following formula: Volume in lots * Contract size / Leverage

Forex No Leverage: This type of calculation is also used for Forex symbols. But unlike the previous one, it does not take into account the trader's leverage: Volume in lots * Contract size

If the script is detecting the symbol as 'No Leverage', then by default shouldn't the leverage be displayed as (1:1), instead of (1:\<current ask price>)? In the original screenshot, the ask price of BTC at the time was 21362.300

ea-output

EarnForex commented 2 years ago

Hello!

Here is what the MQL5 help file says about SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE: Screenshot 2022-06-30 154035

And indeed, if you open a trade of 1 lot, then you'll see that it takes 1/10 of margin, which is consistent with 0.1 Margin Rate application.

So, in reality, even though it says "Forex No Leverage", it would be 1:10 real leverage.

EarnForex commented 2 years ago

Doesn't look like a Position Sizer issue at this time.