Checking Order Comment in MQL4

 

Hello,

If there is another position with the same Comment, I do not want a new order to be opened. I wrote a method for this, but it is not working. I am getting a false response in the "if(OrderType()==orderT)" part, and it allows opening a position.

 There is only one open position and it is OP_BUY. The position I am trying to test is also OP_BUY.  How can OrderType()==orderT be??

I would appreciate your help.


// Example : checkOrder(1.08911,cComment,OP_BUY)

bool checkOrder(double price,string checkComment,int orderT){

   bool result = true;
   if(OrdersTotal()>0)  
     {
     Print("1");
      
      for(int i=OrdersTotal()-1;i>=0;i++) 
        {
         if(OrderSelect(i,SELECT_BY_POS)) 
           {
          
            
              Print("2");
            if(OrderType()==orderT) 
              {
              Print("3");
               if(OrderComment()==checkComment) 
               {
                  result= false;
                  
                Print(" Order Comment: " + OrderComment() + "/" "Check Comment: " + checkComment);
               }
           }//İf
        
        }
        } //For End

     }//Orders Total End

   return result; // No Open Orders
       
    
}
 

Don't use order comment to identify orders and positions, the broker might/will change it!

Use the MagicNumbers for your trading. It is your ID and is not changed by the broker.

 
Carl Schreiber #:

Don't use order comment to identify orders and positions, the broker might/will change it!

Use the MagicNumbers for your trading. It is your ID and is not changed by the broker.


Well, apart from the magic number, how can I understand this order was sent by this EA?

 
Umut Altındağ #:

how can I understand this order was sent by this EA?

This is exactly what the magic number is for.

 
Vladislav Boyko #:

This is exactly what the magic number is for.

I was wondering if there is a different method, thank you.
 
Umut Altındağ #:
I was wondering if there is a different method, thank you.

Different method can almost always be found. For example, you can cook dumplings in an electric kettle. But usually such methods are much worse than traditional ones.