Total profit of closed orders

 

Hello,

I'm new to mql4 so I have some confusion. I want to get the total profit of all orders closed in my last trade ( i have a hedge trade). I know that you can get the profit from OrderProfit but how can you select the trade to get its info if the order is already closed?

Please help...

 
Okay I got it. by using order history. But I dont want to get the info of the last order alone, I want all the orders that were open in my last trade since i have multiple orders open in my hedge trade. how do select only those orders?
 
 

Thanks but this seems to use MagicNumber. I know thats a value you can assign when you create the order but since I open a new hedge as soon as my old one is closed wouldnt the same magicnumber be assigned to the new orders also and they would select both old and new orders from the pool? Could use MathRand but that does not maintain magicnumbers through restart of mt4. Some hash function? Probably best to close all trades before restart but then yuo cant account for s system hiccup right?

Also, do you know any way to close all profitable trades first? I'm getting huge drawdown when my hedge trade closes all the negative orders first.....

 

MagicNumber is your reference. It can be different for each order, or the same. You can use a range of numbers. Whatever works for your EA. Manual Orders (I suspect) have Magic of zero. So if you are closeing manual orders that would be different..

To close profitable orders first do two separate loops.

Also Profit = OrderProfit + OrderSwap + OrderComission.

 
So then this means that OrderComission() will return a negative number right?
 
BeLikeWater:
So then this means that OrderComission() will return a negative number right?

Reason: