Help: Determine closed order if profit or loss

 

Good day,

Can anyone help me with a simple code to know if the last order closed(manual or stop loss) is profit or loss?


I am trying to learn how to make a martingale EA that only doubles the lot if a previous order was a loss then reverts back to 0.10 lot if it gets a profit.


Thanks in advance.

 

Hi deth

First you must successfully select the order, then you can use the functions OrderOpenPrice() and OrderClosePrice() to calculat the profit or loss. Also yo can use OrderCloseTime() to determine if the order is closed or still open (the time will be 0 if the order is not yet closed).

Cheers

Jellybean

 
Jellybean:

Hi deth

First you must successfully select the order, then you can use the functions OrderOpenPrice() and OrderClosePrice() to calculat the profit or loss. Also yo can use OrderCloseTime() to determine if the order is closed or still open (the time will be 0 if the order is not yet closed).

You must select the last non-canceled order from history, OrderCloseTime is irrevelent.

for(int i=HistoryTotal()-1;i>=0;i--) {

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) {
Print("Error in history!"); break;
}
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
int profit=OrderProfit();
}
if (profit > 0) {...}

 

thanks guys for the idea and the code

Reason: