
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
Ok, I see Ask price is used here. That's contrary to the tests I performed on OrderCalcProfit() and tick values.
Could you please check OrderCalcProfit() function and Tick values at the moment of position closure?
Edit:
I did not check the deal_profit field. I do not know if deal_profit == OrderCalcValue() == TICK_VALUE_xxx. I only checked the latter pair. If there is a mismatch, then both the function and tick_values are misleading.
I think there is big misunderstanding between us as several issues were discussed and mixed.
Ok, I will test it tomorrow like this:
Ok, I will test it tomorrow like this:
Ok please also record the rates at closure time if possible.
To be honest I didn't find a logic which works in all cases, I am confused now. On the real account I talked about, I checked 132 trades from history, on these 116 were matching my custom profit/loss calculations, but 16 doesn't match and seems to use the bid instead of the ask or the ask instead of the bid. Maybe I am getting wrong rates from history.
So yes it's better to check live and record the results.
Thank you.
2. Actually, all buy orders uses -> TV_LOSS, all sell use -> TV_PROFIT. (the order_type decides which tick value to use.)
5. TICK_VALUE_XXX is a shortcut to avoid all of these calculations. (the value itself is calculated internally in the software as follows):
6. So, you can calculate profit using a simple calculation like:
From my observations the tick values and tick size are not that accurate in the tester so they are not reliable in historical data, Sometimes even poor internet connection affects this values too, I had to check for that condition in my risk settings library
Ok, this is a proof based on numbers from the terminal (not theories).
I ran the test on two different terminal, one with an account currency = EUR, the other's account currency is USD.
First I use a script, to open positions on all forex symbols on the market watch using a large position size as possible. I increased the demo balance to the maximum 100K to do the tests.
Then, I used a second script "2. AnalyzePositionProfits_Script.mq5" to analyze profits of all open positions, using these methods:
The script outputs the results to csv file. I always use Ron's CSV editor to read csv files. https://www.ronsplace.ca/Products/RonsEditor/Download
Here is the result from the EUR account:
Here is the result from the USD account:
As can be seen POSITION_PROFIT is sometimes (but not always) equal to profit calculation using OrderCalcProfit(). The reason for this may be a timing (sync) issue between the ticks on the server used to calculate the POSITION_PROFIT field and the later ticks reaching the terminal. So, my conclusion is that the value of the POSITION_PROFIT field is calculated on the server, independent of the quote data arriving to the terminal in that exact moment.
All the other methods are matching my previous calculations:
Thanks Amrali,
I will check all of that and post my conclusions, but not in short term as I am very busy.
Forum on trading, automated trading systems and testing trading strategies
Serious bug in the OrderCalcProfit() function
Alain Verleyen, 2023.02.19 23:21
The problem is the profit/loss of this trade was -227.59 EUR.
So the real calculation was :
double profit = volume*contract*(close-open)*GetExchangeRate("AUD","EUR",BUY); /*Rate = 1/Ask*/
= 0.07*100,000*(1.70407-1.75114)*(1/1.44774);
= -227.59 EUR
This is a trade from a real account.
How I "did" what ?
How I "did" what ?
The trade you posted was a close-by one.
Not at all.
I did nothing, it's all "normal" trades open and close in a standard way, CLOSE_BY was not used.