How do you call a function from within a second function? Online help is not cutting it - page 3

 
whroeder1:
  1. Yes a separate thread could have, so what? The point I made was a separate thread could delete/remove/close earlier trades and that changes positions and must be accounted for. Other threads adding later positions are irrelevant.
  2. Read the link previously provided. It shows examples how OrderSelect would return false.





Ok... so I want to confirm that I understand what you're saying... for example if the pool size is 10 and your index is on 8, but 5 orders get deleted which shrink the pool to 5, OrderSelect(8,..) would return false despite orders still in the pool.

I rarely use the standard way of looping orders and use a library that loops and adds ticket numbers of orders that match criteria to a collection... and then loop the collection, selecting by ticket numbers for processing... I have seen the error in my ways. 

 
nicholishen:

Ok... so I want to confirm that I understand what you're saying... for example if the pool size is 10 and your index is on 8, but 5 orders get deleted which shrink the pool to 5, OrderSelect(8,..) would return false despite orders still in the pool.

I rarely use the standard way of looping orders and use a library that loops and adds ticket numbers of orders that match criteria to a collection... and then loop the collection, selecting by ticket numbers for processing... I have seen the error in my ways. 


Now that I think of it, the same could apply the other way as well, no? Say you add 5 tickets in the middle of a std for(int i = Orderstotal()-1;i>=0;i--) loop it could push orders you need to process outside of your loop scope. So I suppose the only fail-safe way to go about it is to add the ticket numbers you want to process to a collection and then go about processing them by ticket and not by position!

 
nicholishen: I rarely use the standard way of looping orders and use a library that loops and adds ticket numbers of orders that match criteria to a collection... and then loop the collection, selecting by ticket numbers for processing... I have seen the error in my ways. 

What that does is process the list n times, once to get the ticket numbers, and then again for each ticket. Not wrong, just inefficient. I do it that way also, if I need to process them in a specific way. The OrderSelect loop down just processes them newest first, (non-fifo #16.)

nicholishen: Say you add 5 tickets in the middle
Impossible. Additions are added to the end.
 
nicholishen:
...
whroeder1:
...

I am not sure what is at stake in this discussion? I don't think you can find a general rule, it all depends of the context.

  • Is there something inside the loop that can delay the execution (trade operations mainly ?) And in general what is done in the loop ?
  • Is it a loop for a symbol/magic only or for all orders ? For open orders or also for pendings ? etc...
  • Is important in your EA to know ASAP about new orders or deleted orders from other EA (or manual) ?

So there is no generic solution equally efficient for all cases, both of your implementations are correct, in a given context, incorrect in other(s).