// --- time interval of the trade history needed datetime end=TimeCurrent(); // current server time datetime start=end-PeriodSeconds(PERIOD_D1)*Days_Order_loockback;// decrease 1 day //--- request of trade history needed into the cache of MQL5 program HistorySelect(start,end); //--- get total number of deals in the history int deals=HistoryDealsTotal(); //--- get ticket of the deal with the last index in the list ulong deal_ticket=HistoryDealGetTicket(deals-1); if(deal_ticket>0) // deal has been selected, let's proceed ot {
//--- ticket of the order, opened the deal ulong order=HistoryDealGetInteger(deal_ticket,DEAL_ORDER); string deal_symbol=PositionGetString(POSITION_SYMBOL); long order_magic=HistoryDealGetInteger(deal_ticket,DEAL_MAGIC); long pos_ID=HistoryDealGetInteger(deal_ticket,DEAL_POSITION_ID);
deal_price=HistoryDealGetDouble(deal_ticket,DEAL_PRICE); deal_volume=HistoryDealGetDouble(deal_ticket,DEAL_VOLUME); deal_profit=HistoryDealGetDouble(deal_ticket,DEAL_PROFIT); // PrintFormat("Deal: #%d opened by order: #%d with ORDER_MAGIC: %d was in position: #%d price: #%f volume: #%f", // deals-1,order,order_magic,pos_ID,deal_price,deal_volume);
} else// error in selecting of the deal {
PrintFormat("Total number of deals %d, error in selection of the deal"+ " with index %d. Error %d",deals,deals-1,GetLastError()); } return(deal_volume); }
does anyone have an idea, that i get only the volume for the last trade in with my MagicNumer in the Symbol back?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
i try to change my mode from the netting mode to the Hedge mode, so i want to selct the histroy order with MagicNumber and Symbol,
i use follofing code
{
double deal_price;
double deal_volume;
double deal_profit;
// --- time interval of the trade history needed
datetime end=TimeCurrent(); // current server time
datetime start=end-PeriodSeconds(PERIOD_D1)*Days_Order_loockback;// decrease 1 day
//--- request of trade history needed into the cache of MQL5 program
HistorySelect(start,end);
//--- get total number of deals in the history
int deals=HistoryDealsTotal();
//--- get ticket of the deal with the last index in the list
ulong deal_ticket=HistoryDealGetTicket(deals-1);
if(deal_ticket>0) // deal has been selected, let's proceed ot
{
//--- ticket of the order, opened the deal
ulong order=HistoryDealGetInteger(deal_ticket,DEAL_ORDER);
string deal_symbol=PositionGetString(POSITION_SYMBOL);
long order_magic=HistoryDealGetInteger(deal_ticket,DEAL_MAGIC);
long pos_ID=HistoryDealGetInteger(deal_ticket,DEAL_POSITION_ID);
deal_price=HistoryDealGetDouble(deal_ticket,DEAL_PRICE);
deal_volume=HistoryDealGetDouble(deal_ticket,DEAL_VOLUME);
deal_profit=HistoryDealGetDouble(deal_ticket,DEAL_PROFIT);
// PrintFormat("Deal: #%d opened by order: #%d with ORDER_MAGIC: %d was in position: #%d price: #%f volume: #%f",
// deals-1,order,order_magic,pos_ID,deal_price,deal_volume);
}
else // error in selecting of the deal
{
PrintFormat("Total number of deals %d, error in selection of the deal"+
" with index %d. Error %d",deals,deals-1,GetLastError());
}
return(deal_volume);
}
does anyone have an idea, that i get only the volume for the last trade in with my MagicNumer in the Symbol back?
amando