EA not recognizing its own orders if trading gold

 

I've been using an EA of my creation for a few years now and it always worked quite well (at least in terms of doing what was expected of it, results are a different story!)..

I've only used it on currencies so far without issues, but recently I tried to apply it to XAUUSD

The result is that the EA seems not to recognize its own orders and keeps opening new ones if it can, or doesn't close the open ones when it should...

Here's the snippet of code that does the order recognition. With currencies it works well.. with XAUUSD it doesn't enter into the if clause. Any ideas?

 

total= OrdersTotal();
int i=0;
for (i=0;i<total;i++)
   {
   OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
   if (OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
      
 
biasibo:

I've been using an EA of my creation for a few years now and it always worked quite well (at least in terms of doing what was expected of it, results are a different story!)..

I've only used it on currencies so far without issues, but recently I tried to apply it to XAUUSD

The result is that the EA seems not to recognize its own orders and keeps opening new ones if it can, or doesn't close the open ones when it should...

Here's the snippet of code that does the order recognition. With currencies it works well.. with XAUUSD it doesn't enter into the if clause. Any ideas?

 

total= OrdersTotal();
int i=0;
for (i=0;i<total;i++)
   {
   OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
   if (OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
      

This code seems ok, except you should check the return value of OrderSelect(). Are you sure the MagicNumber is good ?

You will probably have to post more code to get help.

 
Print out your variables, and find out why.
 

Alain Verleyen, what do you mean with being sure the MagicNumber is good? are there any "bad" magic numbers? Are there restrictions in length for example? is that what you mean?

 

whroeder1: I'll be printing out all the variables at some point probably... but so far everything seems to be pointing at some issue with the magic number, maybe at the broker's level (I'm with Oanda by the way).


Thanks for your fast reply guys :)

 
It could be that the position already has been closed by StopLoss or TakeProfit.
 
Carl Schreiber:
It could be that the position already has been closed by StopLoss or TakeProfit.

unfortunately that's not the case. Orders created by the same EA in the same session are not recognized. 

The point is that the EA worked beautifully on, say, EUR/USD, but developed this issue when I applied it to XAUUSD (without modifying it, it is not coded in a "pair-specific" way)

 
biasibo:

Alain Verleyen, what do you mean with being sure the MagicNumber is good? are there any "bad" magic numbers? Are there restrictions in length for example? is that what you mean?


No, I was just suggesting to double check that your EA magic number is the same as your existing trades. Maybe I misunderstood the problem.
 
  1. Alain Verleyen: No, I was just suggesting to double check that your EA magic number is the same as your existing trades. Maybe I misunderstood the problem.
    Exactly why I said to print the variables. You would find the OrderMagicNumber vs your MagicNumber (or order is closed) is the why.
  2. biasibo: whroeder1: I'll be printing out all the variables at some point probably...
    There are no mind readers here. Find out why.
 
for (int i=OrderTotal()-1;i>=0;i--)
Reason: