Code a function that returns the correct lot size basing on two inputs: stop loss and balance to risk

Trabajo finalizado

Plazo de ejecución 11 días
Comentario del Cliente
_Techno_ did a great job that no one else on the Forums was able to do. He is a real pro and the code delivered works perfectly and with any broker and is easy to read and as optimized as it can get. Communication was always prompt and on time and very professional and friendly as well. I can highly recommend him!

Tarea técnica

Hello Coders,

I am looking for a function (not a complete EA, but a function that I can use from any of my EA´s that I code) that I simply can call like:


Lotsize = ExampleLotFunction(BalanceToRiskInPercent, StopLossPrice);

so for example with values:

Lotsize = ExampleLotFunction(2, 1.23456);


... and it returns the correct lot-size to risk exactly 2% of my current Account balance in my base-currency with the StopLoss passed to it and taking into account the account-base-currency and ANY conversions needed of course if the pair I trade is not in the account-base-currency (example: trading the AUDNZD on a account with the base currency EUR). I have found code on the forum that does work correctly if my account-base-currency is included in the pair that I trade (example: EUR is the account-base-currency and I trade EURUSD), but none yet that calculates correctly if trading AUDNZD, GBPCAD, NZDJPY or whatever and my account-base-currency is in EUR. Hence this request here in the hope someone can finally code something like this for me:)

The code should be of good quality and just be in a simple complete function so that I can use it for any of the EA´s I will be coding in the future without creating a mess and just should take those 2 input variables: Percent of current account balance to risk for the current trade by taking into account the stop loss I´ve passed to it.

Of course it should also be highly adaptive and should have no hard-coded constraints, meaning that it should adapt to different account-base-currencies, 4 and 5 digit brokers, check for the correct lot-step, lot-min and lot-max, etc. etc. Just what a professional function requires.

Thank you:)


P.S.: IMPORTANT: THS IS FOR MT4, not MT5 !


Han respondido

1
Desarrollador 1
Evaluación
(473)
Proyectos
1138
44%
Arbitraje
51
31% / 33%
Caducado
500
44%
Libre
2
Desarrollador 2
Evaluación
(187)
Proyectos
367
56%
Arbitraje
45
22% / 56%
Caducado
188
51%
Libre
3
Desarrollador 3
Evaluación
(24)
Proyectos
98
83%
Arbitraje
4
0% / 25%
Caducado
9
9%
Libre

Información sobre el proyecto

Presupuesto
10 - 30 USD
IVA (19%): 1.9 - 5.7 USD
Total: 11.9 - 35.7 USD
Para el ejecutor
9 - 27 USD