Referencing long & short closed trades together
6 replies
glennc
6 years ago #203095
Hello, thank you for such an excellent program.
I want to obtain total profit from last x-number of trades, long and short combined.
If I separate the longs and the shorts with magic numbers, won’t that give me totals for last x long trades and last x short trades, which is not the same as last x trades combined?
If I use zero as magic number, won’t that include trades of other EAs of the same currency pair running on the platform?
How do I solve this? I have other problems related to this type of issue, this is one example of the problem.
tomas262
6 years ago #203217
Hello,
in EA Wizard you can use Sum Of Closed PL to check longs only / shorts only having the same magics for all longs or all shorts. If you use magic = 0 it will count orders across all pairs traded not only one you place your EA on
glennc
6 years ago #203230
Hi Thomas,
Thanks for your reply.
So to confirm: I simply cannot derive profit/loss over a certain number of trades, regardless of trade direction??
This would seem an unfortunate limitation. As I mention above, this question is one example of a bigger issue. If magic = 0 cannot contain itself to only the EA in question, then surely we need a function that allows
magicLong AND magicShort or magicLong OR magicShort?
tomas262
6 years ago #203403
To obtain total profits of # of historical trades you can do this function (place at the end of EAWizard \ code \ CustomFunction.mq4)
int sqGetTotalPL(int numberOfLastOrders) {
double pl = 0;
int count = 0;
int profits = 0;for(int i=OrdersHistoryTotal(); i>=0; i–) {
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true && OrderSymbol() == Symbol()) {count++;
if(OrderType() == OP_BUY) {
pl = (OrderClosePrice() – OrderOpenPrice());
} else {
pl = (OrderOpenPrice() – OrderClosePrice());
}if(pl > 0) {
profits++;
}if(count >= numberOfLastOrders) break;
}
}return(profits);
}
You can then reference it using Custom Function functionality in EA Wizard using call “sqGetTotalPL(3)” to obtain P/L for last 3 trades on a selected symbol
glennc
6 years ago #203693
Hi Tomas,
Thank you very for that – I appreciate the time it must take. As I read through the code (keeping in mind that I can’t read code), will this give me a result only for the EA it is included in, and not all results for the pair (OrderSymbol) in the MT4 history? I am trying to isolate the profit/loss over a number of trades within a specific EA, even though other EAs are running on the same pair on the same platform.
Thanks again for your help.
tomas262
6 years ago #203816
Hello,
this statement in the code OrderSymbol() == Symbol() ensures that it will give you results only for the symbol you run your EA on for example EURUSD
glennc
6 years ago #217747
Thanks Tomas!
Viewing 6 replies - 1 through 6 (of 6 total)