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

Experten Bibliotheken

Auftrag beendet

Ausführungszeit 11 Tage
Bewertung des Kunden
_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!

Spezifikation

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 !


Bewerbungen

1
Entwickler 1
Bewertung
(473)
Projekte
1138
44%
Schlichtung
51
31% / 33%
Frist nicht eingehalten
500
44%
Frei
2
Entwickler 2
Bewertung
(187)
Projekte
367
56%
Schlichtung
45
22% / 56%
Frist nicht eingehalten
188
51%
Frei
3
Entwickler 3
Bewertung
(24)
Projekte
98
83%
Schlichtung
4
0% / 25%
Frist nicht eingehalten
9
9%
Frei

Projektdetails

Budget
10 - 30 USD
MwSt (19%): 1.9 - 5.7 USD
Insgesamt: 11.9 - 35.7 USD
Für die Entwickler
9 - 27 USD