I am trying to modify the following code to return the last deal price by order type in history. Can anyone help. The code as is, is returning the last open price, but does not distinguish between BUYS or SELLS.
//+------------------------------------------------------------------+ //| return Opening Price for last BUY deal in History | //+------------------------------------------------------------------+ double LastDealBuyOpenPrice() { uint pos_total=0; uint total=0; long pos_id=0; ulong HTicket=0; double price=0; pos_total=PositionsTotal();
if(pos_total>0) {
if(PositionSelect(Symbol()) && TYPE_LONG) // continue if open position is for chart symbol and order type { pos_id=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER); HistorySelectByPosition(pos_id); total=HistoryDealsTotal(); HTicket=HistoryDealGetTicket(total-1); // get ticket number for last deal in position
//+------------------------------------------------------------------+ //| return Opening Price for last SELL deal in History | //+------------------------------------------------------------------+ double LastDealSellOpenPrice() { uint pos_total=0; uint total=0; long pos_id=0; ulong HTicket=0; double price=0; pos_total=PositionsTotal();
if(pos_total>0) {
if(PositionSelect(Symbol()) && TYPE_SHORT) // continue if open position is for chart symbol and order type { pos_id=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER); HistorySelectByPosition(pos_id); total=HistoryDealsTotal(); HTicket=HistoryDealGetTicket(total-1); // get ticket number for last deal in position
I am trying to modify the following code to return the last deal price by order type in history. Can anyone help. The code as is, is returning the last open price, but does not distinguish between BUYS or SELLS.
//+------------------------------------------------------------------+
//| return Opening Price for last BUY deal in History |
//+------------------------------------------------------------------+
double LastDealBuyOpenPrice()
{
uint pos_total=0;
uint total=0;
long pos_id=0;
ulong HTicket=0;
double price=0;
pos_total=PositionsTotal();
if(pos_total>0)
{
if(PositionSelect(Symbol()) && TYPE_LONG) // continue if open position is for chart symbol and order type
{
pos_id=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER);
HistorySelectByPosition(pos_id);
total=HistoryDealsTotal();
HTicket=HistoryDealGetTicket(total-1); // get ticket number for last deal in position
if(HTicket>0)
price=HistoryDealGetDouble(HTicket,DEAL_PRICE);
return(price);
}
}
return(0);
}
//+------------------------------------------------------------------+
//| return Opening Price for last SELL deal in History |
//+------------------------------------------------------------------+
double LastDealSellOpenPrice()
{
uint pos_total=0;
uint total=0;
long pos_id=0;
ulong HTicket=0;
double price=0;
pos_total=PositionsTotal();
if(pos_total>0)
{
if(PositionSelect(Symbol()) && TYPE_SHORT) // continue if open position is for chart symbol and order type
{
pos_id=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER);
HistorySelectByPosition(pos_id);
total=HistoryDealsTotal();
HTicket=HistoryDealGetTicket(total-1); // get ticket number for last deal in position
if(HTicket>0)
price=HistoryDealGetDouble(HTicket,DEAL_PRICE);
return(price);
}
}
return(0);
}