hi all, I need to check the opened and closed orders after the start of the current bar.
Is this code correct? I'm not sure.
You need OrdersHistoryTotal() if looping through closed orders
OrdersTotal() is for open orders.
In addition to the above, the orders start at index 0 (not 1) so really it should be:
As you have it, the final order select is going to fail, but it won't cause any major issue because the OrderSymbol check will also fail.
In any event, it is best to count down, rather than up when dealing with orders - see here
You will need 2 loops, one for the open orders and one for the closed orders.
I'd also recommend adding
to your code. It would have flagged up at least one warning with the code you have posted (to check the return value of OrderSelect). I'm sure it will help with other sections of your code.
For orders (and objects) one better should make it as a personal habit to count down - in case you want to delete/close them and you are re-using (copy & paste) your own code!
It will check 0, but if he had written:
then it would not check 0.
I enjoy reading Carl's posts - he often has a slightly different way of looking at things (PS typo on the first line = not ==)
Of course. I am an idiot. I always get confused with that :)
That's why I never use anything like that.