Download MetaTrader 5

EA not recognizing its own orders if trading gold

To add comments, please log in or register
Thousands of developers have already published their products in the Market. Join them!
biasibo
14
biasibo 2016.11.08 20:51 

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())
      
Alain Verleyen
Moderator
30731
Alain Verleyen 2016.11.08 21:01  
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.

whroeder1
14504
whroeder1 2016.11.08 21:16  
Print out your variables, and find out why.
biasibo
14
biasibo 2016.11.08 21:26  

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 :)

Carl Schreiber
6589
Carl Schreiber 2016.11.08 21:33  
It could be that the position already has been closed by StopLoss or TakeProfit.
biasibo
14
biasibo 2016.11.08 21:38  
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)

Alain Verleyen
Moderator
30731
Alain Verleyen 2016.11.08 23:13  
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.
whroeder1
14504
whroeder1 2016.11.09 16:52  
  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.
eevviill6
27
eevviill6 2016.11.09 20:40  
for (int i=OrderTotal()-1;i>=0;i--)
To add comments, please log in or register