Yep, use Magic Numbers.
You can then either code your own means to track the trade, or simply connect the account to one of the sites offering trade explorers that can break down by magic number and symbol.
Loop through closed orders and sum profit for those with the magic number and symbol.
If you need to check open orders, loop through the open orders and add those with the magic number and symbol.
GumRai:
I am using the code below to try and loop through closed orders and then sum profits by symbol with no success (I did change OrdersTotal() to OrdersHistoryTotal() and MODE_TRADES to MODE_HISTORY). Can you help? I am trying to return the total profit for ALL trades of one symbol in the Account History tab (prefer not to use Magic #s). Thanks in advance for your assistance.
{ int i, iOrders = OrdersTotal() - 1; //defining running parameter for below double sum_profits = 0; for(i = iOrders; i >= 0; i--) { OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); if( Symbol() == OrderSymbol() && OrderMagicNumber() == Magic ) { sum_profits += OrderProfit(); } } return( sum_profits );
}
GumRai:
I am using the code below to try and loop through closed orders and then sum profits by symbol with no success (I did change OrdersTotal() to OrdersHistoryTotal() and MODE_TRADES to MODE_HISTORY). Can you help? I am trying to return the total profit for ALL trades of one symbol in the Account History tab (prefer not to use Magic #s). Thanks in advance for your assistance.
}
I don't see anything wrong with the code that you have posted.
It should give you net profits for open orders that are of the chart symbol and the EA's magic number.
If you prefer to check without the magic number, then remove the check.
Show your code for checking closed trades.
I don't see anything wrong with the code that you have posted.
It should give you net profits for open orders that are of the chart symbol and the EA's magic number.
If you prefer to check without the magic number, then remove the check.
Show your code for checking closed trades.
Here my code. The sum profit seemingly changes when an order for the symbol has not closed (I run the EA on several charts/symbols)
{ int i, iOrders = OrdersHistoryTotal() - 1; double sum_profits = 0; for(i = iOrders; i >= 0; i--) { OrderSelect( i, SELECT_BY_POS, MODE_HISTORY); if( Symbol() == OrderSymbol()) ) { sum_profits += OrderProfit(); } } return( sum_profits );
if( Symbol() == OrderSymbol()) )
Does the code compile?
You seem to have a stray close bracket
Does the code compile?
You seem to have a stray close bracket
No, it did not compile. However, I changed to a custom function (see below), but it still does not seem to calculate correctly. Is the code correct to sum the total of ALL profits for a particular symbol of ALL closed orders of that symbol found in the Account History tab?
double Money()
{
double sum_profits = 0;
int i, iOrders = OrdersHistoryTotal() - 1; //defining running parameter for below
for(i = iOrders; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)==true)
{
if( Symbol() == OrderSymbol()) sum_profits += OrderProfit();
}
}
return( sum_profits );
}
The only thing that I can see is that you don't include commisions and swaps,
sum_profits += OrderProfit()+OrderCommission()+OrderSwap();
The only thing that I can see is that you don't include commisions and swaps,
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys,
Is there any way to keep track of the profit that the same EA has made per pair while trading?
Thanks