OrderLots() is half what it should be

 
   
         if(direction==25)
      {
       for(int i=OrdersTotal()-1;i>=0;i--)
          {
          if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            if(OrderMagicNumber()==MagicNumber)
               if(OrderSymbol()==Symbol())                                                                 
                  if(OrderType()==OP_BUY)
                   if(OrderTicket()==buyticket2 && OpenOrdersThisPair(Symbol())==5){OrderClose(buyticket2,OrderLots(), bid,7,Yellow);Print(OrderLots());}
          }
      }
      
Any mistakes here? only half of my order get's closed.
 
r u closing only buy positions on this Symbol() ?
 
qjol:
r u closing only buy positions on this Symbol() ?

No I'm closing sell positions also, why do you ask?
 
MetaNt:
Any mistakes here? only half of my order get's closed.

Within your OpenOrdersThisPair function do you have an OrderSelect() ? if you do then the OrderSelect() in the code posted above is potentially no longer valid . . . as you have selected a different Order.

Change your Print() to . .

Print("OrderLots: ", OrderLots(), " OrderTicket: ", OrderTicket(), " buyticket2: ", buyticket2);

. . . and you will see that OrderTicket != buyticket2

 
RaptorUK:

Within your OpenOrdersThisPair function do you have an OrderSelect() ? if you do then the OrderSelect() in the code posted above is potentially no longer valid . . . as you have selected a different Order.

Change your Print() to . .

. . . and you will see that OrderTicket != buyticket2


This is what I was in denial of.... I kept running into issues using OpenOrderThisPair along with orderselect() when I tried to duplicate the error in a different environment.
 
MetaNt:

No I'm closing sell positions also, why do you ask?

use

OrderClosePrice()
 
qjol:

use


In place* of?
 
RaptorUK:

Within your OpenOrdersThisPair function do you have an OrderSelect() ? if you do then the OrderSelect() in the code posted above is potentially no longer valid . . . as you have selected a different Order.

Change your Print() to . .

. . . and you will see that OrderTicket != buyticket2


OrderTicket = 4 buyticket2=8, anarchy. Here is what I don't understand, I use

OrderClose(buyticket2,OrderLots(), bid,7,Yellow);Print(OrderLots());

I specify the orderticket value....

 

u can't close a sell pos with Bid (B.T.W. it's Bid no bid (B is capital)) therefore my suggestion is to use OrderClosePrice()

OrderClose(buyticket2,OrderLots(), OrderClosePrice(),7,Yellow);Print(OrderLots());
 
qjol:

u can't close a sell pos with Bid (B.T.W. it's Bid no bid (B is capital)) therefore my suggestion is to use OrderClosePrice()


Oh yeah my bid = MarketInfo(ect); it isn't a sell order it's a buy order. I tried it and the problem persists, problem fixed.

fix = remove OrdersOpenThisPair (which works out anyway since the orderopenthispair is part of the condition).

 
MetaNt:


I specify the orderticket value....

Yes you do . . . but you have selected the wrong order so OrderLots() is wrong for buyticket2 . . . follow your code through . . .

if(OrderTicket()==buyticket2 && OpenOrdersThisPair(Symbol())==5){OrderClose(buyticket2,OrderLots(), bid,7,Yellow);Print(OrderLots());}


First

if(OrderTicket()==buyticket2

OK,

next

&& OpenOrdersThisPair(Symbol())==5)

this function uses OrderSelect() so now you have a different Order selected . . . not buyticket2

next

{OrderClose(buyticket2,OrderLots(), bid,7,Yellow);Print(OrderLots());}

OrderLots() is wrong . . .


You can test a dirty change . .. it's not a fix, it's not even a workaround . . . it's just for testing . . .

if(OrderTicket()==buyticket2 && OpenOrdersThisPair(Symbol())==5)
   {
   OrderSelect(buyticket2, SELECT_BY_TICKET);       // selects the correct Order so . . .
   OrderClose(buyticket2,  OrderLots(), OrderClosePrice(), 7, Yellow);  // . . . OrderLots() works.
   Print(OrderLots());
   }
Reason: