Try this.
//+------------------------------------------------------------------+ //| return Total Deals in current open position | //+------------------------------------------------------------------+ int TotalDeals() { uint pos_total=0; uint total=0; long pos_id=0; pos_total=PositionsTotal(); if(pos_total>0) { // continue if current open position if(PositionSelect(Symbol())) // continue if open position is for chart symbol { pos_id=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER); HistorySelectByPosition(pos_id); total=HistoryDealsTotal(); } } return(total); }
wackena:
Try this.
Thanks for the quick response. It is returninng the cumulative total in history. What I want is the number of deals within the current open position. That means it has to reset to zero when the position is liquidated. The count restarts when a new position is established.
I hope I am clear.
Thanks for your help
Documentation on MQL5: Trade Functions / HistoryDealsTotal
- www.mql5.com
Trade Functions / HistoryDealsTotal - Documentation on MQL5
Lets loop through all potential open Positions and then select chart symbol to find position deals.
//+------------------------------------------------------------------+ //| return Total Deals in current open position | //+------------------------------------------------------------------+ int PositionDeals() { uint pos_total=0; uint total=0; ulong pos_id=0; pos_total=PositionsTotal(); if(pos_total > 0) { for(uint i=0;i<pos_total;i++) { if(PositionSelect(Symbol())) { pos_id=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER); HistorySelectByPosition(pos_id); total=HistoryDealsTotal(); return(total); } } } return(0); }
wackena:
Thanks buddy.
Lets loop through all potential open Positions and then select chart symbol to find position deals.
wackena:
Lets loop through all potential open Positions and then select chart symbol to find position deals.
There is no need for loop
//+------------------------------------------------------------------+
//| die Anzahl der Deals der offenen Position des Symbol |
//+------------------------------------------------------------------+
int PositionDeals()
{
uint total=0;
ulong pos_id=0;
if(PositionSelect(Symbol()))
{
pos_id=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER);
HistorySelectByPosition(pos_id);
total=HistoryDealsTotal();
return(total);
}
return(0);
}
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am trying to figure out the total open deals in an open position. I am using the following code but it seems to return the value of PositionsTotal() instead of the total deals within the position. Can someone help.
Once again it seems I would have to call on both Rosh and Wackena to help me resolve this coding issue.
//+------------------------------------------------------------------+
//| return Total Deals in current open position |
//+------------------------------------------------------------------+
int TotalDeals()
{
uint pos_total=0;
uint total=0;
long pos_id=0;
ulong HTicket=0;
int count=0; // I added initial default value
pos_total=PositionsTotal();
if(pos_total>0)
{ // continue if current open position
if(PositionSelect(Symbol())) // continue if open position is for chart symbol
{
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)
if(PositionGetInteger(POSITION_MAGIC)==MagicNumber)
{
count++;
}
return(count);
}
}
return(0);
}