Profit of the last trade?

 

Hi All,

Can anyone help me reading the profit of the last closed trade?

Many thanks in advance and good trades!

X55

 
x55:
Hi All,

Can anyone help me reading the profit of the last closed trade?

Many thanks in advance and good trades!

X55

Try this:

OrderSelect(HistoryTotal() , SELECT_BY_POS,MODE_HISTORY);

if(OrderType() == OP_BUY)

Print("Last order profit was: ",(OrderClosePrice()-OrderOpenPrice());

else

Print("Last order profit was: ",(OrderOpenPrice()-OrderClosePrice());

 

Kalenzo,

Many thanks for this snippet!

 

I don't know what am I doing wrong , I am trying to find the profit /loss of the last order so I wrote the following functions and I am not getting the answer that I want , any suggestions help is highly appreciated

double GetLastPL()

{ double TempLastOrderProfit=0; int hstTotal=OrdersHistoryTotal();

datetime CloseTime; for(i=0;i<hstTotal;i++)

{ //---- check selection result if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)

{ if ((OrderSymbol() == Symbol() && OrderMagicNumber() == iMagic) && OrderCloseTime()>CloseTime)

{ if (OrderCloseTime()>CloseTime) CloseTime= OrderCloseTime();

TempLastOrderProfit= OrderProfit() + OrderSwap()+ OrderCommission();

} } }

Print( "Last Order Profit loss was " , TempLastOrderProfit); }
 
MiniMe:
I don't know what am I doing wrong , I am trying to find the profit /loss of the last order so I wrote the following functions and I am not getting the answer that I want , any suggestions help is highly appreciated

double GetLastPL()

{ double TempLastOrderProfit=0; int hstTotal=OrdersHistoryTotal();

datetime CloseTime; for(i=0;i<hstTotal;i++)

{ //---- check selection result if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)

{ if ((OrderSymbol() == Symbol() && OrderMagicNumber() == iMagic) && OrderCloseTime()>CloseTime)

{ if (OrderCloseTime()>CloseTime) CloseTime= OrderCloseTime();

TempLastOrderProfit= OrderProfit() + OrderSwap()+ OrderCommission();

} } }

Print( "Last Order Profit loss was " , TempLastOrderProfit); } [/PHP]

Use this function :

[PHP]double GetLastPL()

{

double TempLastOrderProfit = 0;

datetime CloseTime = 0;

for(int i=OrdersHistoryTotal()-1;i>=0;i--)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

if (OrderSymbol() == Symbol() && OrderMagicNumber() == iMagic && OrderCloseTime()>CloseTime)

{

CloseTime = OrderCloseTime();

TempLastOrderProfit = OrderProfit() + OrderSwap()+ OrderCommission();

}

}

return(TempLastOrderProfit);

}

It assumes that you have a variable named iMagic as a global variable and will return a last profit for current chart symbol + that magic number

 

Thanks a lot Mladen,

The magic number was the problem , I have a function that creates a magic number for each new order and I forgot to call the magic number

Regards,

Fadi

Reason: