Problem with total amount of open orders - page 3

 
You need to show your whole modified code.
 
Print your variables before and inside if statements and find out why.
 
WHRoeder:
Print your variables before and inside if statements and find out why.

Ok thank you, I will do that and research this more.  I also found this bit of code which intrigues me because the SL and TP is separated from OrderSend.  Will look into this as well

ticket = OrderSend( Symbol(), OP_SELL, getPositionSize(), Bid, 3, 0, 0, "Basic CCI EA", magic, 0 , Red );
         OrderModify( ticket, OrderOpenPrice(), Bid + SL, Bid - TP, 0 );
 

Hi Everyone

I have fixed most of my issues and the EA works fine in the tester, but I'm still having issues with OrdersTotal. In Demo mode it will sometimes open both pending Stop orders, but most of the time only the buy or the sell.  I want both pending orders to open at the same time (within a few seconds), but only if no other orders or pending orders are open.  I think what happens is that sometimes it opens both pending orders before it has a chance to calculate the number of orders, and other times it actually realize that a pending order got send, and won't open the other one.  I thought that if I put the Ordersends within curly brackets it will excecute both when the if condition is met?  I also now know that it will continue to open pending orders when I delete them for as long as the last candle is being formed, i.e. as long as the Time variable matches the Time[0] candle, ticks are irrelevant.

 

Here is that bit of code:

extern datetime StartTime1 = D'2016.03.15 15:05';
int start(){
int buy_ticket=0, sell_ticket=0, buystop_ticket=0, sellstop_ticket=0, total=0;
   for(int i= OrdersTotal()-1; i>= 0; i--)
      if(OrderSelect(i,SELECT_BY_POS) && OrderMagicNumber()==magic && OrderSymbol()==Symbol())
        {
         total++;
         if(OrderType()==OP_BUYSTOP) buystop_ticket=OrderTicket();
         if(OrderType()==OP_SELLSTOP) sellstop_ticket=OrderTicket();
         if(OrderType()==OP_BUY) buy_ticket=OrderTicket();
         if(OrderType()==OP_SELL) sell_ticket=OrderTicket();
        }

   if(total==0 && Time[0]==StartTime1)
     {
      buystop_ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Price,30,Ask-SL,0,"Pending",magic,0,Lime);
      sellstop_ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Price,30,Bid+SL,0,"Pending",magic,0,Red);
     }

 So is there a better or easier way for me to do this?  Thank you

 
Trader3000:

Hi Everyone

I have fixed most of my issues and the EA works fine in the tester, but I'm still having issues with OrdersTotal. In Demo mode it will sometimes open both pending Stop orders, but most of the time only the buy or the sell.  I want both pending orders to open at the same time (within a few seconds), but only if no other orders or pending orders are open.  I think what happens is that sometimes it opens both pending orders before it has a chance to calculate the number of orders, and other times it actually realize that a pending order got send, and won't open the other one.  I thought that if I put the Ordersends within curly brackets it will excecute both when the if condition is met?  I also now know that it will continue to open pending orders when I delete them for as long as the last candle is being formed, i.e. as long as the Time variable matches the Time[0] candle, ticks are irrelevant.

 

Here is that bit of code:

 So is there a better or easier way for me to do this?  Thank you

Are you checking the value of  buystop_ticket and sellstop_ticket ? If there is only 1 open, the second will never be open (unless you remove the first manually).
 
Trader3000 I also found this bit of code which intrigues me because the SL and TP is separated from OrderSend.  Will look into this as well
ticket = OrderSend( Symbol(), OP_SELL, getPositionSize(), Bid, 3, 0, 0, "Basic CCI EA", magic, 0 , Red );
         OrderModify( ticket, OrderOpenPrice(), Bid + SL, Bid - TP, 0 );
When ECN brokers started, the OrderSend would fail with SL/TP set. Most have fixed this since build 600.
 
zirkoner:
Are you checking the value of  buystop_ticket and sellstop_ticket ? If there is only 1 open, the second will never be open (unless you remove the first manually).

Thank you for the reply.  Actually both buystop and sellstop orders open about 50% of the time.  The other 50% of the time either the buy or sell get send.  But I did find something out.  I asked for the last error and on those occurences where both get send, there are no errors, but when only one opens, I get error 130 on the one that did not open.  So it appears as if my stops are invalid, but I don't know why.  Here is the code for SL:

extern int StopLossOriginal=11;

int start(){
int stoplevel=(MarketInfo(Symbol(),MODE_STOPLEVEL))/10;
   if(StopLossOriginal<=stoplevel) StopLossOriginal=stoplevel;

double point=Point*10,
       Price=Pipmove*point,
       SL=(StopLossOriginal-Pipmove)*point;

 if(total==0 && (Time[0]==time1)
     {
      buystop_ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Price,30,Ask-SL,0,"Pending",magic,0,Lime);
      Print("Buystop ticket =",buystop_ticket);
      sellstop_ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Price,30,Bid+SL,0,"Pending",magic,0,Red);
      Print("Sellstop ticket =",sellstop_ticket);
     }

 Also I added the Print function.  Is that what you meant with "Are you checking the value of  buystop_ticket and sellstop_ticket ? "?  It returns two values namely: 

 2016.03.24 17:11:22.532 News_v10 GBPUSD,M1: Buystop ticket =-1

 2016.03.24 17:11:23.227 News_v10 GBPUSD,M1: Buystop ticket =49644335



 
WHRoeder:
When ECN brokers started, the OrderSend would fail with SL/TP set. Most have fixed this since build 600.
Thank you for your reply.  I tried this as well but it didn't make a difference.  I'm on build 950
 
Trader3000:

Thank you for the reply.  Actually both buystop and sellstop orders open about 50% of the time.  The other 50% of the time either the buy or sell get send.  But I did find something out.  I asked for the last error and on those occurences where both get send, there are no errors, but when only one opens, I get error 130 on the one that did not open.  So it appears as if my stops are invalid, but I don't know why.  Here is the code for SL:

 Also I added the Print function.  Is that what you meant with "Are you checking the value of  buystop_ticket and sellstop_ticket ? "?  It returns two values namely: 

 2016.03.24 17:11:22.532 News_v10 GBPUSD,M1: Buystop ticket =-1

 2016.03.24 17:11:23.227 News_v10 GBPUSD,M1: Buystop ticket =49644335



You need to add RefreshRates() between your 2 OrderSend().
 
zirkoner:
You need to add RefreshRates() between your 2 OrderSend().
Whoot Whoot!  That worked.  Thank you very much
Reason: