How to check open profit?
1 replies
boomza100
12 years ago #111237
Is there a way check the total open account profit?
For example, if I have 4, 5 or 10 open trades, over different currencies, AUDUSD, USDJPY etc …, some in profit, some in loss, I want to close all trades if my open profit is at some level.
I was using Open P/L (in pips), with magic number set to 0, but it only seemed to read the profit for the one currency.
Any thoughts?
Thanks.

Mark Fric
12 years ago #121826
Hi,
it is possible only using custom function. Open the file {EA Wizard installation}/code/CustomFunctions.mq4
and add the following function there:
double sqGetTotalOpenPLInPips() {
double pl = 0;
for (int cc = OrdersTotal() – 1; cc >= 0; cc–) {
if (!OrderSelect(cc, SELECT_BY_POS) ) continue;
if(OrderType() != OP_BUY && OrderType() != OP_SELL) continue;
if(OrderType() == OP_BUY) {
pl += Bid – OrderOpenPrice();
} else {
pl += OrderOpenPrice() – Ask;
}
}
return(pl*gPointPow);
}
this will add new function to the program that will be attached to every EA generated by EA Wizard.
Then you can call this new function in Functions -> Custom Function or Then actions -> Other -> Custom Action.
You’ll call it normally like GetTotalOpenPLInPips()
Your condition could be for example:
IF Custom Function: GetTotalOpenPLInPips() > 1000
THEN
…do something
Mark
StrategyQuant architect
Viewing 1 replies (of 1 total)