Download MetaTrader 5

Simple Question on OrderTotal()

To add comments, please log in or register
airified
78
airified  

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)

Keith Watford
Moderator
10070
Keith Watford  

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 

airified
78
airified  
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!!
To add comments, please log in or register