Hi All,
Can anyone help me reading the profit of the last closed trade?
Many thanks in advance and good trades!
X55Try 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); }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

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
Can anyone help me reading the profit of the last closed trade?
Many thanks in advance and good trades!
X55