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
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
![Forum rules and recommendations Forum rules and recommendations](https://c.mql5.com/36/80/forum-rules-and-recommendations__4.jpg)
Forum rules and recommendations
- 2023.03.12
- www.mql5.com
Each language has its own forum, and it is therefore forbidden to communicate in any language other than that of the forum in question...
Vladislav Boyko #:
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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
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]