Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hey guys, I am a bit stuck and need help.
I am currently coding a semi-automatic MT4 EA for order placement and management. The idea is, that I insert these variables:
1) Order direction (buy/sell)
2) Start price (e.g. 2800)
3) End price (e.g. 2798)
4) SL (e.g. 2802)
5) TP1 (2796)
6) TP2 (2794)
7) TP3 (2792)
8) Risk percentage (e.g. 3%)
9) Number of orders (e.g. 30)
For the sake of this example, lets assume 100k USD account, so the max loss/risked amount is 3k USD. The max loss (and therefore lot size per order) shall be calculated based on actual account balance. Leverage and any other variable shall be fetched automatically per instrument (not per account). The EA must work on any broker and any instrument and calculate risk/lot size correctly based on the inputs stated above.
Now there are two scenarios:
1) Only Start price is set, so that all 30 orders shall be set at 2800, all with same SL and various TP1/2/3. All the orders shall be evenly sized (all the same size), respecting the max loss of 3k USD in total.
2) Both Start and End price are set, so that the EA shall distribute 30 orders evenly in the range between 2800 and 2798. All the orders shall be evenly sized (all the same size), respecting the max loss of 3k USD in total.
Here is the problem.
I have created the following code, but after attaching it to various instruments (XAUUSD, EURUSD, BTCUSD and USDJPY so far), the EA calculates incorrect lot sizes. I tried to iterate the code using AI in order to find the problem, but with no success. Does anyone of you have idea what am I doing wrong? Any ideas are highly appreciated.