Download MetaTrader 5

OrderLots() is half what it should be

To add comments, please log in or register
Are you a good trader? Become a signals provider and make even more money!
Luciano Ola
1007
Luciano Ola 2014.02.12 21:11 
   
         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.
qjol
3243
qjol 2014.02.12 21:17  
r u closing only buy positions on this Symbol() ?
Luciano Ola
1007
Luciano Ola 2014.02.12 21:24  
qjol:
r u closing only buy positions on this Symbol() ?

No I'm closing sell positions also, why do you ask?
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.02.12 21:30  
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

Luciano Ola
1007
Luciano Ola 2014.02.12 21:31  
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.
qjol
3243
qjol 2014.02.12 21:38  
MetaNt:

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

use

OrderClosePrice()
Luciano Ola
1007
Luciano Ola 2014.02.12 21:59  
qjol:

use


In place* of?
Luciano Ola
1007
Luciano Ola 2014.02.12 22:16  
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....

qjol
3243
qjol 2014.02.12 22:34  

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());
Luciano Ola
1007
Luciano Ola 2014.02.12 22:49  
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).

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.02.12 23:28  
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());
   }
123
To add comments, please log in or register