MT5 Miscalculated forex lotszie when base account is BTC or something with high value!

You can try any strategy on an account where BTC or other high-value crypto is the account currency and FOREX is the market and fixed % of account is the mm type. OR just trust me and use your thinking, obv bitcoin should not be rounded to two decimal places. 

(This is incorrect, it should be placing lot size 0.07 NOT 0.01) 

2022.03.16 10:15:03.324 2.17.390-eu-m15-m.mql (EURUSD,M15) ---VERBOSE--- 2022.03.16 20:15 Computing Money Management for order -  Risk fixed % of account
2022.03.16 10:15:03.324 2.17.390-eu-m15-m.mql (EURUSD,M15) ---VERBOSE--- 2022.03.16 20:15 Computing Money Management - Smallest_Lot: 0.01000000, Largest_Lot: 100.00000000, Computed LotSize: 0.00000000
2022.03.16 10:15:03.324 2.17.390-eu-m15-m.mql (EURUSD,M15) ---VERBOSE--- 2022.03.16 20:15 Max money to risk: 0.00000000, SL:1.09314000, Max 1 lot trade drawdown: 0.02000000, Point value: 2.48434860
2022.03.16 10:15:03.324 2.17.390-eu-m15-m.mql (EURUSD,M15) ---VERBOSE--- 2022.03.16 20:15 Calculated LotSize is <= 0. Using LotsIfNoMM value: 0.01000000)

I found the problem. My account is BTC so I need more than 2 decimals. I don't think you need to normalize here anyways, it might be redundant....


//Maximum amount of money to risk double moneyToRisk = NormalizeDouble(AccountInfoDouble(ACCOUNT_EQUITY) * RiskInPercent / 100, 2); //Maximum drawdown of this order if we buy 1 lot double oneLotSLDrawdown = NormalizeDouble(PointValue * MathAbs(openPrice - sl), 2);



Needs to be this
(or needs to autodetect account type and normalize with way more decimals for crypto)



//Maximum amount of money to risk double moneyToRisk = AccountInfoDouble(ACCOUNT_EQUITY) * RiskInPercent / 100; //Maximum drawdown of this order if we buy 1 lot double oneLotSLDrawdown = PointValue * MathAbs(openPrice - sl);





And now I get this which shows my code is working properly now:


2022.03.16 10:45:03.226 12.17.335-eu-m15-m (EURUSD,M15) ---VERBOSE--- 2022.03.16 20:45 Computing Money Management for order -  Risk fixed % of account
2022.03.16 10:45:03.226 12.17.335-eu-m15-m (EURUSD,M15) ---VERBOSE--- 2022.03.16 20:45 Computing Money Management - Smallest_Lot: 0.01000000, Largest_Lot: 100.00000000, Computed LotSize: 0.07000000
2022.03.16 10:45:03.226 12.17.335-eu-m15-m (EURUSD,M15) ---VERBOSE--- 2022.03.16 20:45 Max money to risk: 0.00216605, SL:1.08762000, Max 1 lot trade drawdown: 0.02847054, Point value: 2.46925774


Attachments
No attachments
  • Votes +4
  • Project StrategyQuant X
  • Type Bug
  • Status Fixed
  • Priority Normal

History

b
#1

bentra

16.03.2022 18:55

Task created

b
#2

bentra

16.03.2022 20:11
Voted for this task.
E
#3

Emmanuel

17.03.2022 13:12
Voted for this task.
CG
#4

Chris G

18.03.2022 03:58
Voted for this task.
b
#5

bentra

18.03.2022 19:57
I don't think there is any reason to normalize those variables. If it is just to make the logs look nice then we should be using print formatting instead of modifying the underlying variables. Other than that the only thing that needs to be normalized is the finalized lot size. This could be a source of other rounding issues even on non crypto base accounts.
HH
#6

Hans

29.03.2022 00:44
Voted for this task.
TB
#7

Tomas Brynda

29.03.2022 07:49

Status changed from New to Fixed

Hi Bentra,

the rounding is there to minimize floating point imprecision issues. 

Sometimes there is a slightly different value representation in SQ and MT and it can causes calculated size differences.


I have modified the templates to round to 7 digits, that should be enough hopefully.


Best regards,

Tomas

b
#8

bentra

29.03.2022 07:55
My account appears to be accurate to 8 but I guess 7 should be fine, thanks.

Votes: +4

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please