Loops and Closing or Deleting Orders - page 2

 

What heppens if the OrderSelect faild to select the order?
The condition OrderMagicNumber==MagicNo would never be true. So no need to check the result of OrderSelect and continue if falid.

it's better if you want to check OrderSelect to decrease the loop variable. Example:

for(PositionIndex = 0; PositionIndex < OrdersTotal() ; PositionIndex ++)  
   {
   if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) { PositionIndex--; continue; }
 
  1. If the orderSelect fails, you might get the last selected order's magic number or something left in memory and that might match. Always check.
  2. You must ALWAYS count down. Supposed while you were working on position 3 position 0 closed. The next order you wanted to work at was position 4 but will be at position 3 when you loop and increment positionIndex to 4. You've now missed one. By counting down you may process the same order a second time but you won't miss any.
 
WHRoeder:
  1. If the orderSelect fails, you might get the last selected order's magic number or something left in memory and that might match. Always check.
  2. You must ALWAYS count down. Supposed while you were working on position 3 position 0 closed. The next order you wanted to work at was position 4 but will be at position 3 when you loop and increment positionIndex to 4. You've now missed one. By counting down you may process the same order a second time but you won't miss any.

1- Who told you that? And which memory you talking about?


2- I didn't mention counting down or up. the code provided itself is not counting down.

 
  1. OrderMagicNumber() and the others ALWAYS return something. If OrderSelect() failed, you get random garbage, left overs, maybe from the previous successful select, maybe for value from the last closed order, maybe what ever is in a register. Ever try to dereference a pointer on a deleted object? Memory, that's the small black chip on the circuit board. Try this
    int start(){    Print(Whatever()); }
    double Whatever(){
       for(i=0; i<10; i++) double tmp=Close[i];
       // no value returned
    }
    and post some output.
  2. I know "the code provided itself is not counting down." That's the problem. Always count down! Your decrement WILL NOT WORK and is a potential infinite loop.
    if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) { PositionIndex--; continue; }

 

Is there a specific reason why you coded: 

if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;

instead of (?)

if( OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) )
{
  // statements if true
}

 I know that it is considered a no-no by some coding standards. Does it give a better performance or is it just preference?

 
burgie:

Is there a specific reason why you coded: 

instead of (?)

 I know that it is considered a no-no by some coding standards. Does it give a better performance or is it just preference?

No specific reason that I remember . . .  I don't really know what is the logical thing to do,  why should OrderSelect() ever fail ? and if it does fail what should be done ? 
 
burgie:

Is there a specific reason why you coded: 

instead of (?)

 I know that it is considered a no-no by some coding standards. Does it give a better performance or is it just preference?

 


Inside a loop, this is exactly the same, choose what you prefer.
 
burgie:

Is there a specific reason why you coded: 

instead of (?)

 I know that it is considered a no-no by some coding standards. Does it give a better performance or is it just preference?

 

 

if(orderselect(......)) execute this  //---no going back

if(!orderselect(.......))continue //go back and check

 
MirTD:

 

if(orderselect(......)) execute this  //---no going back

if(!orderselect(.......))continue //go back and check

I already answered the question that was asked of me about my coding . . .
Reason: