Download MetaTrader 5
To add comments, please log in or register
Any problems with the code? Find solution in documentation!
Kenley
59
Kenley 2014.02.11 16:50 

Code that used to work just fine now no longer works as expected.

For example, the following function no longer works:


 bool ExistPositions(string Name_Expert) {
   int count=0;
   for (int j=0; j<OrdersTotal(); j++) {
      if (OrderSelect(j, SELECT_BY_POS, MODE_TRADES))
         if (OrderSymbol() == Symbol() && OrderComment()==Name_Expert) return (TRUE);
   }
    return (FALSE); 
}

I run multiple strategies in a single EA and use the ordercomments to distinguish between which strategy is being executed.

The code above used to check if an order already existed based on ordercomments. It no longer works correctly with build 600 which is resulting in multiple orders flooding into my account.

Why does this no longer work?


Ubzen
Moderator
5394
Ubzen 2014.02.11 17:07  
//Try comparing the Print-Out values

bool ExistPositions(string Name_Expert) {
   int count=0;
   for (int j=0; j<OrdersTotal(); j++) {
      if (OrderSelect(j, SELECT_BY_POS, MODE_TRADES)){
         Print("===================================");
         Print("Name_Expert=",Name_Expert);
         Print("OrderComment()=",OrderComment());
         Print("OrderSymbol()=",OrderSymbol());
         Print("Symbol()=",Symbol());
         if (OrderSymbol() == Symbol() && OrderComment()==Name_Expert) return (TRUE);
      }
   }
    return (FALSE); 
}
Kenley
59
Kenley 2014.02.11 17:52  

It prints out as expected and the logic has worked soundly for years pre-build 600.

In my order open logic i use the following:

if(!ExistPositions("strategyName")){OrderSend...

For some reason, even though Order already exists and the comment is written correctly, the Ordersend is firing.

Could this be weirdness with the ordercomment string now being unicode? Something else?

qjol
3243
qjol 2014.02.11 18:01  

B.T.W.

WHRoeder: Said

Not a good idea, brokers can change comments, including complete replacement. Instead I'd use a range of magic numbers.

Ubzen
Moderator
5394
Ubzen 2014.02.11 18:05  
kenleyl:

It prints out as expected and the logic has worked soundly for years pre-build 600.

In my order open logic i use the following:

For some reason, even though Order already exists and the comment is written correctly, the Ordersend is firing.

Could this be weirdness with the ordercomment string now being unicode? Something else?

Thats what I'm trying to find out. I'm starting with the simple cases and working my way up.

I'll try creating a simple case EA and see if I can duplicate the error. Your code is too incomplete for that.

Kenley
59
Kenley 2014.02.11 18:07  
qjol:

B.T.W.


Again, this has worked reliably with my broker for years, pre-b600. I'm trying to figure out why its not working all of the sudden.

I can see the comments haven't been changed by my broker or anyone else. However, multiple orders are now being opened with the same ordercomment.

graziani
1895
graziani 2014.02.11 18:12  
i am comparing strings successfully in b604, however you can try StringCompare().
Ubzen
Moderator
5394
Ubzen 2014.02.11 18:28  

I cannot re-create the duplication of orders. Are you sure it isn't something else within your code?

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void start(){
   if(ExistPositions("TestingA")) return;

   int iTicket=OrderSend(
      Symbol(),      //string   symbol,              // symbol
      OP_SELL,       //int      cmd,                 // operation
      0.1,           //double   volume,              // volume
      Bid,           //double   price,               // price
      0,             //int      slippage,            // slippage
      0,             //double   stoploss,            // stop loss
      0,             //double   takeprofit,          // take profit
      "TestingA",     //string   comment=NULL,        // comment
      7,             //int      magic=0,             // magic number
      0,             //datetime expiration=0,        // pending order expiration
      clrRed         //color    arrow_color=clrNONE  // color
   );
   
   if(iTicket<=0) Print("OrderSend_Failed***");

}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool ExistPositions(string Name_Expert) {
   int count=0;
   for (int j=0; j<OrdersTotal(); j++) {
      if (OrderSelect(j, SELECT_BY_POS, MODE_TRADES)){
         Print("===================================");
         Print("Name_Expert=",Name_Expert);
         Print("OrderComment()=",OrderComment());
         Print("OrderSymbol()=",OrderSymbol());
         Print("Symbol()=",Symbol());
         if (OrderSymbol() == Symbol() && OrderComment()==Name_Expert) return (TRUE);
      }
   }
    return (FALSE); 
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kenley
59
Kenley 2014.02.12 20:50  

I appreciate the detailed response and investigation. It is possible that some conditional OR logic is evaluated differently now. I do notice that there are several warnings that appear when i compile with the new build that I never saw pre-b600.

I'm going to revert back to a demo account, clean up all the warnings, and forward test a few months before going live again. After I identify root cause I'll circle back.

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.12 20:55  
kenleyl:

I appreciate the detailed response and investigation. It is possible that some conditional OR logic is evaluated differently now.

The precedence of OR and AND ( || and && ) has changed . . . to avoid confusion and misinterpretation use ( ) braces.
/
To add comments, please log in or register