Write a function to calculate maximum lot size for the given percentage margin of risk

MQL5 Scripts Integration

Job finished

Execution time 1 day
Feedback from customer
Great work, thanks.

Specification

I need the following function to complete:

double GetMaxLotSize(int cmd, double sl, double risk_margin = 1.0, string symbol = NULL)

Arguments are:

- cmd: Command such as OP_BUY or OP_SELL.

- sl: Stop loss to calculate the lot size for.

- risk_margin: Account margin to risk (in %), e.g. Money = AccountBalance() / 100 * risk_margin (e.g. 1.0%)

-  symbol: If NULL, means current.

The output:

- Maximum safe lot size value to use where given SL won't exceed the percentage of risk margin amount.

This should work similar as GetMaxStopLoss() which calculates the maximum SL for given lot size, but GetMaxLotSize should work other way round.

The code should be compatible with MQL4 and MQL5. 

Responded

1
Developer 1
Rating
(590)
Projects
789
71%
Arbitration
9
33% / 33%
Overdue
22
3%
Free
Published: 8 codes
2
Developer 2
Rating
(119)
Projects
127
41%
Arbitration
3
33% / 67%
Overdue
0
Free
3
Developer 3
Rating
(97)
Projects
121
25%
Arbitration
5
20% / 60%
Overdue
17
14%
Free
4
Developer 4
Rating
(133)
Projects
185
30%
Arbitration
77
9% / 73%
Overdue
77
42%
Free
5
Developer 5
Rating
(39)
Projects
81
38%
Arbitration
1
0% / 0%
Overdue
31
38%
Free

Project information

Budget
15 - 20 USD
Deadline
from 1 to 3 day(s)