Quick Programming Question
Page 1 of 732 12 LastLast
Results 1 to 10 of 313

Thread: Quick Programming Question

  1. #1
    I've noticed the following loop is widely and routinely used for counting, closing or deleting orders, etc:

    Inserted Code for (int I = OrdersTotal() #91;colour=red#93;-1#91;/colour#93;; I gt;= 0; I--)
    My question is why can we use the -1 piece of the code? Is this logically correct while we would like to include all orders in our search? Isn't this just when looking for candles and we would like to exclude the 0 candle?

    Enjoy your clarifiion.

  2. #2
    Let's say that there are 10 orders for orderstotal. Even though it would be human nature to rely on them 1 through 10, computers like to make things difficult and number them 0 through 9. So we subtract 1 to compensate for this.

  3. #3
    The Orders variety is a zero based array as well as the OrdersTotal is one based the requirement to subtract.

    Hence the first order in the list is not Order(1) but Order(0).

    Make sense?

    Lux

  4. #4
    Quote Originally Posted by ;
    The Orders variety is a zero based selection and the OrdersTotal is just one based therefore the requirement to subtract one.

    So the first order in the list Isn't Order(1) but Order(0).

    Make sense?

    Lux
    Thank you for the rapid response both and luxinterior.

    I happened to know that the numbering of orders at the list of active (market pending) and closed orders begins with zero but to me personally if the total of the orders is 10 then with OrdersTotal()-1 the system must count from 8 to 0, then ignoring the last order, not out of 9 to 0.

  5. #5
    Quote Originally Posted by ;
    Thanks for the rapid reply both and luxinterior.

    I happened to understand [font=Verdana] the numbering of orders in the list of active (market pending) and shut orders starts with zero but to me if the total of the orders is 10 then with OrdersTotal()-1 [color=black]the system must count in 8 to 0, then ignoring the last order, perhaps not out of 9 ...
    accurate if 10 - 1 = 8

  6. #6
    Quote Originally Posted by ;
    Thanks for the rapid response both and luxinterior.

    I happened to know [font=Verdana] the numbering of orders in the list of active (market impending) and closed orders starts with zero but to me if the total of the orders is 10 then with OrdersTotal()-1 [color=black]the system must count from 8 to 0, ignoring the previous order, perhaps not from 9 to...
    instance 5 orders index 0,1,2,3,4

    5-1 = 4

    countdown
    4 3 2 1 0 = still 5 orders

    see
    http://www.codersource.net/c_arrays_tutorial.html

  7. #7
    OK, will it present the machine with a problem if I don't subtract 1 or is it only to make the system more effective ?

  8. #8
    Quote Originally Posted by ;
    OK, will it present a problem to the system if I don't subtract 1 or is it just to make the system more efficient ?
    Its similar to this:

    array[index] =gt; appreciate

    array with two elements

    array[0] =gt; either value1 or order1 or ...
    array[1] =gt; value2 or order2 or ...

    sizeof array is two

    for(begin, while, do)

    for(I = 2; I gt;= 0; I--) ... 2, 1, 0

    but you dont possess array[2] array with index 2

    depending on the programming language, It Is Going to Provide you an error or a value from pc memory you dont need or want to, either way its better to begin within the array, in this situation you want to start from index 1 and count to zero, therefore you substract 1 in the size of the array (in this case 2)

    so that it looks like

    for(I = size -1; I gt;= 0; I--) ... 1, 0 thats what you want

  9. #9
    Thank you and invite you all others that responded.

  10. #10
    Quote Originally Posted by ;
    OK, will it present a problem to the system if I do not subtract 1 or is it just to make the system more efficient ?
    Won't hurt anything.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.