hey guys
I think I have the same problem with selecting more than one position among all positions with some specific properties like Comments, tickets or buy or sell. I use the code attached but it seems it doesn’t work correctly. for selecting one position its ok but more than one position with the same identifiers it is showing wrong outcomes.
I want to select all buy positions which have “B1” comment with different Symbols (for example, EURUSD, GBPUSD and USDJPY) and calculate their profit.
//+------------------------------------------------------------------+
//|B1 profit calculator Function |
//+------------------------------------------------------------------+
double B1profit(void){
CPositionInfo pi;
CTrade trade;
double B1Prf=0;
int i,j;
for(i=0;i<CROSS_NUMBER;i++){
for(j=0;j<MAX_LEVEL;j++){
if(pi.SelectByTicket(baseTickets[i][j])&&pi.Comment()=="B1"&&pi.PositionType()==POSITION_TYPE_BUY){
B1Prf += pi.Profit();//+PositionGetDouble(POSITION_SWAP); //*********//commision is omited
}
}
}
return B1Prf;
}
//+-----------------------------------------------