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

仕事が完了した

実行時間11 日
依頼者からのフィードバック
_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!

指定

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 !


応答済み

1
開発者 1
評価
(473)
プロジェクト
1139
44%
仲裁
51
31% / 33%
期限切れ
501
44%
2
開発者 2
評価
(187)
プロジェクト
367
56%
仲裁
45
22% / 56%
期限切れ
188
51%
パブリッシュした人: 1 article, 6 codes
3
開発者 3
評価
(24)
プロジェクト
98
83%
仲裁
4
0% / 25%
期限切れ
9
9%
パブリッシュした人: 6 codes

プロジェクト情報

予算
10 - 30 USD