I know that OrdersTotal() and OrdersTotal() - 1 both return current market pending and running order. But i don't know the difference between the two. An explanation would be helpful.
OrdersTotal()
is the number of market + pending orders. After you have that number, you can loop over the orders (either from OrdersTotal()-1
to >=0
, or from 0 to <OrdersTotal()
. If you loop from the top, you call OrdersTotal() function just once, that is a minor improvement to speed. What is more important, if you loop from 0 and close / delete some order in the middle, you can jump over the next order and leave it unchecked. So this may cause a bug. Loop from the top to zero seems to be a best practice.