# Profit of the last trade?

10

Hi All,

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

X55

1413

x55:
Hi All,

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

X55

Try this:

OrderSelect(HistoryTotal() , SELECT_BY_POS,MODE_HISTORY);

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

else

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

10

Kalenzo,

Many thanks for this snippet!

2127

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); }
168309

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

2127

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,