Sum Open Profit Long/Short for Specified Symbol
0 replies
tomas262
6 years ago #117426
If you need to get current open profit for specified symbol you can use the following function in EA WIzard
1) add custom code into CustomFunction.mq4 placed in Wizard folder
float sumOpenProfit(string direction, string symbolString) { float totalProfit = 0; for(int i=OrdersTotal()-1; i>=0; i--) { if (OrderSelect(i,SELECT_BY_POS)==true) { if (direction == "LONG" && symbolString != "" && OrderType() == OP_BUY && OrderSymbol() == symbolString) { totalProfit += OrderProfit(); } else if (direction == "LONG" && symbolString == "" && OrderType() == OP_BUY) { totalProfit += OrderProfit(); } else if (direction == "SHORT" && symbolString != "" && OrderType() == OP_SELL && OrderSymbol() == symbolString) { totalProfit += OrderProfit(); } else if (direction == "SHORT" && symbolString == "" && OrderType() == OP_SELL) { totalProfit += OrderProfit(); } } } return totalProfit; }
2) add CustomAction like this in Wizard
Get open P/L from longs in EURUSD
sumOpenProfit("LONG", "EURUSD");
or
get open P/L for all shorts active
sumOpenProfit("SHORT", "")
example EA is attached