thanks for your reply, it is solved now because I found the source of problem. There wasn’t any wrong parameters in my code. In the closing part of my code based on my strategy it closes one basket having “B1” comment and the half of the other one with “B2” comment, I found that when the half of a position is closed the comment will be deleted, so in the next processes it can’t be found as a position with “Bla Bla” comment. :)))
//+------------------------------------------------------------------+
//|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;
}
//+------------------------------------------------------------------+
//|B1 close Function |
//+------------------------------------------------------------------+
bool B1close(void)
{
CPositionInfo pi;
CTrade trade;
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)
{
if(!trade.PositionClose(pi.Ticket()))
{
PrintFormat("Position B1Close Error = %d",GetLastError());
return(false);
}
}
if(pi.SelectByTicket(baseTickets2[i][j]) && pi.Comment()=="B2" && pi.PositionType()==POSITION_TYPE_SELL)
{
if(!trade.PositionClosePartial(pi.Ticket(),pi.Volume()/2))
{
PrintFormat("Position B1@PClose Error = %d",GetLastError());
return(false);
}
}
}
}
}