Why does this code not produce sells? - page 2

 
Marco vd Heijden:
Check the return value of OrderSend()
Under expert tab you mean? Just sais the ticket numbers there.
 
Carl Schreiber:
Have you gone through your code with the debugger?

Well Id never done that before. I clicked the debugger in MetaEditor and nothing happened.


 Gotta be a way to fix this problem.

 

Your code is opening orders (although Marco is correct - you should check the return value in case of failure, and Carl is correct you shouldn't use NULL that way) and the logic is working as you have asked - see my post here.

I guess you're after something more like this:

   if (sellcount_order()==0 && /*more conditions to open first sell order*/) 
      {
      OrderSend(Symbol(),OP_SELL,.01,NULL,NULL,NULL,NULL,1,1,NULL,NULL);
      }
   if (buycount_order()==0 && /*more conditions to open first buy order*/)
      {
      OrderSend(Symbol(),OP_BUY,.01,NULL,NULL,NULL,NULL,1,1,NULL,NULL);
      }
   if (sellcount_order()==1 && /*more conditions to open second buy order*/) 
      {
      OrderSend(Symbol(),OP_BUY,.01,NULL,NULL,NULL,NULL,2,2,NULL,NULL);
      }
   if (buycount_order()==1 && /*more conditions to open second sell order*/)
      {
      OrderSend(Symbol(),OP_SELL,.01,NULL,NULL,NULL,NULL,2,2,NULL,NULL);
      }
 
nadiawicket:

Well Id never done that before. I clicked the debugger in MetaEditor and nothing happened.


 Gotta be a way to fix this problem.

If the green button in the editor to start the debugger is grey (not available) just do this:

  1. File => Save as
  2. choose the same name (you can use always a new one - but then you have to delete them afterwards)
  3. confirm overwriting
  4. now you have a chance to start the debugger.

If I try to debug an indicator with b1045 or b1052 it isn't working.

If so I can send you the old terminal b1031 but without any guaranty - you might have to delete the content of the config folder!

Don't forget to place Breakpoints (F9) to stop the debugger at specific lines!

 
  1. Your codeDocumentation
    OrderSend(
       Symbol(),
       OP_SELL,
       .01,
       NULL,
       NULL,
       NULL,
       NULL,
       1,
       1,
       NULL,
       NULL
    );
    int  OrderSend(
       string   symbol,              // symbol
       int      cmd,                 // operation
       double   volume,              // volume
       double   price,               // price
       int      slippage,            // slippage
       double   stoploss,            // stop loss
       double   takeprofit,          // take profit
       string   comment=NULL,        // comment
       int      magic=0,             // magic number
       datetime expiration=0,        // pending order expiration
       color    arrow_color=clrNONE  // color
       );
    NULL is not a valid price (double.) NULL is not a valid slippage (points.) NULL is not a valid SL (price.) NULL is not a valid TP (price.) NULL is not a valid datetime (expiration.) NULL is not a valid color.
  2. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
 

Thanks all !! Got it down finally. Was a logic issue.

if (sellcount_order()==0 )
   {
   OrderSend(Symbol(),OP_SELL,.01,Bid,0,0,0,1, 1 ,0,clrNONE); 
   }
if (buycount_order()==0 )
   {
   OrderSend(Symbol(),OP_BUY,.01,Ask,0,0,0,1, 1 ,0,clrNONE); 
   }
if (sellcount_order()==1  && secondbuycount_order()==0)
   {
   OrderSend(Symbol(),OP_BUY,.01,Ask,0,0,0,2, 2 ,0,clrNONE); 
   }
if (buycount_order()==1 && secondsellcount_order()==0)
   {
   OrderSend(Symbol(),OP_SELL,.01,Bid,0,0,0,2, 2 ,0,clrNONE); 

Second counter and magic numbers did it