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)
项目
1138
44%
仲裁
51
31% / 33%
逾期
500
44%
空闲
2
开发者 2
等级
(187)
项目
367
56%
仲裁
45
22% / 56%
逾期
188
51%
空闲
发布者: 1 文章, 6 代码
3
开发者 3
等级
(24)
项目
98
83%
仲裁
4
0% / 25%
逾期
9
9%
空闲
发布者: 6 代码

项目信息

预算
10 - 30 USD
VAT (19%): 1.9 - 5.7 USD
总计: 11.9 - 35.7 USD
开发人员
9 - 27 USD