Cycle Operator 'for' questions - page 13

 

Simon,

"Your   while  loop did not find any ticket  . . . ."

It didn't "possibly" find the ticket index in the History pool, it did find it or the following functions wouldn't have been executed. :)


" a pool index != a ticket number  haven't we been through this before ?"

Let me clarify now,

An order ticket number is the unique ticket number assigned to an order once the request has been sent.

An order position number is an order's position in an order pool index (important to understand) similar to an array.


"why do you expect the closed USDJPY Order to end up in the same position in a completely different pool,  the History pool ?"

I shouldn't because it is a separate pool.

In the code I presented-

   if(OrderType()==OP_BUY){bid_ask=MarketInfo("USDJPY",MODE_BID);}
   if(OrderType()==OP_SELL){bid_ask=MarketInfo("USDJPY",MODE_ASK);}
   if((OrderStopLoss()!=0)&&(OrderTakeProfit()!=0))
   if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)&&(OrderSymbol()=="USDJPY"))
     {      
      OrderClose(OrderTicket(),OrderLots(),bid_ask,3,CLR_NONE);

      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
      
      Print(OrderCloseTime());
     }

this is apparently selecting the order from the history pool right? At least this is what I gathered from Documentation. Also I recently tried opening about five orders on separate currency pairs, closed one, then turned on the EA and it still performed all functions including Print(OrderCloseTime());.


Thank you.

 
WhooDoo22:

Simon,

"Your   while  loop did not find any ticket  . . . ."

It didn't "possibly" find the ticket index in the History pool, it did find it or the following functions wouldn't have been executed. :)

Which functions are you using that use a ticket number ?  your OrderSelects are all SELECT_BY_POS   . . .  POS meaning POSition,  so I repeat,  your while loop does not find a ticket it finds an index in the Order pool.


What you are selecting from the History pool is the Order at index position  i   how do you KNOW  that the order you just closed is at position  i  ?  the answer is you do not KNOW . . .  you value of  i  is where the USDJPY Order was in the Order pool . . . .   the pools are completely separate and not linked in any way shape or form.
 

Simon,

"your while loop does not find a ticket it finds an index in the Order pool."

Yeah, I believe I understand this. This shouldn't be an issue.


"the pools are completely separate and not linked in any way shape or form."

This is understood yet the OrderClose() function code block seems to work as it is intended. I'll adjust the code block to save the order ticket number value so as to continue with what you wish to address. Agreed?

FIRST, I will ask this question: Why wouldn't an order's history pool position number not be the same as its present pool position number? I believe this number to be the same.


Thank you.

 
WhooDoo22:

Simon,

"your while loop does not find a ticket it finds an index in the Order pool."

Yeah, I believe I understand this. This shouldn't be an issue.


"the pools are completely separate and not linked in any way shape or form."

This is understood yet the OrderClose() function code block seems to work as it is intended. 

There was no change to the OrderClose() call so it should still work.


However, this does not work as intended because the concept is fatally flawed . . .  until you understand why there is no point in continuing . . .

 if(OrderType()==OP_BUY){bid_ask=MarketInfo("USDJPY",MODE_BID);}
   if(OrderType()==OP_SELL){bid_ask=MarketInfo("USDJPY",MODE_ASK);}
   if((OrderStopLoss()!=0)&&(OrderTakeProfit()!=0))


   if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)&&(OrderSymbol()=="USDJPY"))
     {      
      OrderClose(OrderTicket(),OrderLots(),bid_ask,3,CLR_NONE);

      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
      
      Print(OrderCloseTime());
     }
 
WhooDoo22:


FIRST, I will ask this question: Why wouldn't an order's history pool position number not be the same as its present pool position number? I believe the number to be the same.


Go to your Demo account that you have been testing with . . .  how many open orders do you have ?  how many Orders do you have in your History in the Account History tab ?
 

Simon,

'Account History' contains fifty six.

'Trade' (open orders) contains three.


I'm waiting for you to write, "I guess it does work WhooDoo. :)"

Hooold on, I checked the returned Print() function ticket number and it returned a different ticket number than the USDJPY order.

Does not work. Confirmed. I'm glad I tried though, this lesson was worth discussion.

Thank you.

 
WhooDoo22:

Simon,

'Account History' contains fifty six.

'Trade' (open orders) contains three.

If you create a new USDJPY Order and run your code and it finds this new order   i   will have a value of 3 ,   what position in the History Pool will your USDJPY order take when you close it ?  there are already 56 so position 3 is already taken, so is position 4, 5, 6,  7  . . .   55
 

Simon,

57.

   if(OrderType()==OP_BUY){bid_ask=MarketInfo("USDJPY",MODE_BID);}
   if(OrderType()==OP_SELL){bid_ask=MarketInfo("USDJPY",MODE_ASK);}
   if((OrderStopLoss()!=0)&&(OrderTakeProfit()!=0))
   if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)&&(OrderSymbol()=="USDJPY"))
     {      
      int usdjpy_ticket_number=OrderTicket();
      
      OrderClose(OrderTicket(),OrderLots(),bid_ask,3,CLR_NONE);

      if(OrderSelect(usdjpy_ticket_number,SELECT_BY_TICKET,MODE_TRADES)==true)
      
      Print("Ticket number for USDJPY = ",usdjpy_ticket_number);
      Print("Order close time = ",OrderCloseTime());
     }

Thank you.

 
WhooDoo22:

Simon,

57.

Thank you.

i  is 3   so how will selecting the order in position 3 in the History Pool manage to get the Order in position 57 ? ?
 

Simon,

It won't. I recently re-discovered this.

Thank you.

Reason: