Download MetaTrader 5
To add comments, please log in or register
Do you often publish source codes? Find out how to do that correctly!
Louis Stoltz
643
Louis Stoltz 2014.02.21 12:50 
/**
  Scan History
**/  

bool InHistory(double magic) 
{
  int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++)
    {
     OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
     if(OrderMagicNumber() == magic) {
        return(TRUE);
        break;
     }
     else {
        return(FALSE);
     }
     
    }
} 

This function of mine does not seem to work, I need help with this.

I want to match with magicnumber and see if same order has opened before

Ubzen
Moderator
5394
Ubzen 2014.02.21 20:51  
bonechair:

This function of mine does not seem to work, I need help with this.

I want to match with magicnumber and see if same order has opened before

/**
  Scan History
**/  

bool InHistory(double magic) <-Magic should be integer not double
{
  int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++) 
    {
     OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);<-Put this within an if() statement
     if(OrderMagicNumber() == magic) {
        return(TRUE);
        break;<-The break is useless because it'll return above.     
     }
     else {<-One way or the other, its going to return true or false on the first check.
        return(FALSE);<-Therefore if the 1st in history doesn't match the magic it returns false
     }
     
    }
} 
Keith Watford
Moderator
7950
Keith Watford 2014.02.21 21:05  
/**
  Scan History
**/  

bool InHistory(double magic) 
{
  int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++)
    {
     OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
     if(OrderMagicNumber() == magic) {
        return(TRUE);
     }
    }
  return(FALSE)  //MOVED THIS RETURN TO OUTSIDE THE LOOP 
} 
/
To add comments, please log in or register