Simple Question on OrderTotal()

 

Hey all, googled for OrderTotal() doc but seems to be missing something.

 Have noticed that for looping through open/pending orders, people use for(i=0, i < OrderTotal(), i++) Or for(i=OrderTotal() - 1, i>=0, i--).

 

Dumb qns but can I check why is it  i=OrderTotal() - 1 and not i=OrderTotal() if I want to check if i have any open orders of a particular currency before opening a new trade? (to prevent holding 2 positions of the same currency)

 

Because indexing starts at 0, whereas counting starts at 1

So if there are 2 open orders, the first one will be indexed 0 and the 2nd will be indexed 1

So the highest index number will always be 1 less than the total 

 
GumRai:

Because indexing starts at 0, whereas counting starts at 1

So if there are 2 open orders, the first one will be indexed 0 and the 2nd will be indexed 1

So the highest index number will always be 1 less than the total 

Hey GumRai thanks for the explanation!!
Reason: