OrderProfit() result value abnormality.
trade.totalLoss += OrderProfit() + OrderCommission() + OrderSwap();
Why do you call this a loss ("totalLoss")? It can also be a profit😄
Let's call it a little differently:
double orderProfit = OrderProfit() + OrderCommission() + OrderSwap(); Then you can add it to whatever you want😄:
double orderProfit = OrderProfit() + OrderCommission() + OrderSwap();
trade.totalLoss += orderProfit; Although, you probably mean something like this:
double orderProfit = OrderProfit() + OrderCommission() + OrderSwap(); if(orderProfit < 0.0) trade.totalLoss += orderProfit; else trade.totalWin += orderProfit;
Well, you get the idea: you do not take into account commission and swap
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
- 2023.03.12
- www.mql5.com
Let's call it a little differently:
Then you can add it to whatever you want😄:
Although, you probably mean something like this:
Well, you get the idea: you do not take into account commission and swap
Thank you for your detailed answer.
The actual usage source is as follows:
for (int i = OrdersHistoryTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false) continue; if (OrderSymbol() == Symbol() && (OrderMagicNumber() == MAGIC_NUMBER || OrderMagicNumber() == MAGIC_NUMBER + 1)) { trade.totalLoss += OrderProfit(); Print(OrdersHistoryTotal(), "-", i, " ", OrderProfit(), " ", trade.totalLoss); if (OrderMagicNumber() == MAGIC_NUMBER) break; } }
I removed the code to print the log.
This is to calculate the previous loss when applying martingale.
This is a phenomenon that occurs occasionally.
The profit in the results window is -12.02, but when printed from the source, it comes out as -8.84.
[Code]