Download MetaTrader 5

Simple Question on OrderTotal()

To add comments, please log in or register
You can test an application before buying it. Find out how to do that!
airified
78
airified 2015.07.14 00:12 

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
9618
Keith Watford 2015.07.14 01:38  

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 2015.07.14 01:55  
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