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
Thanks for your effort, I have posted the code in the message above.
BTW I checked for OrderCalcProfit threads, but nothing did any help for me. Either it was much to specific for little, little effects I think I am not looking for. It's not about half a percent off expectation, but we are talking about a factor of 100 (!!!) I am missing. Well, quite a few of those threads are to high-level for me, I was simply not able to understand...
One potential issue with your code is that you're calling OrderCalcProfit(), with price parameters, inside of OnInit(). Based on my past experience, prices are not loaded when OnInit() runs.
See the placement of OrderCalcProfit() in the documentation:
I used KI to write a CustomOrderCalcProfit function. It calculates the profit exactly as I would expect it. And as it proves in reality, well that's quite a point I think ;-) .
Now I asked KI to explain that. Based on the values I fed in the exptected result is -640 while the internal OrderCalcProfit function returns -256. The KI explains like this:
Can someone adjust this? Usually I refrain from writing "better code than the platform I use" because while writing I find out how smart the platform is and erase my code - whilst learning important lessons. But here I don't have any more ideas...
@Alain Verleyen It seems you are very active here and had a deep, smart look into this already. Do you have any idea about it?
Forum on trading, automated trading systems and testing trading strategies
Trying calculate trade result / OrderCalcProfit
Alain Verleyen, 2026.05.21 21:22
If you want clear answer, you need to provide clear information (screenshots, logs, etc...). No idea about the factor so you are talking about (100 ?).
Are you trading real futures or CFD ?
We have no idea about the context of your last post. Where are coming these -640/-256 ? Where is the code that produced these values ? I will not try to guess sorry.
An AI claiming there is a "fundamental flaw by MetaQuotes" is a bit ironic. An MT5/MQL5 bug is possible, though evidences should be provided to reproduce it : code + broker server used.