Cycle Operator 'for' questions - page 7

 

Simon,

So if OrdersTotal() returns 10  what is the last and first order position ?

I have used the OrdersTotal() function as a condition before using OrderSend() functions. To my understanding I have used the OrdersTotal() function in a fashion such as this:

if(OrdersTotal()<1) OrderSend(...);

// I have also used the function like this...

if(OrdersTotal()==0) OrderSend(...);

Both above code lines represent something like, if there are no orders presently send an order.

OrdersTotal() function Returns market and pending orders count (this can also be written: Returns total current market orders and total pending orders count).

I am assuming 'Order ticket position' runs in a similar fashion then. It begins with 1 and ends with 10 (personally I wouldn't jump to this conclusion based on OrdersTotal() function value representation but progress must be made).

if OrdersTotal() returns 10, the first position is 1 and last position 10. So the current position for the most recent order is 10 and the first order placed (10th in succession) is 1.

Thank you.

 

@WhooDoo22:if OrdersTotal() returns 10, the first position is 1 and last position 10. = false.
- Hence the correct answer is 0 and 9 accordingly
- The 1st Position=0 && The Last Position = OrderTotal - 1
- Why do you keep saying "Order Ticket Position"
- It's either "Order Ticket" or "Order Position"
- Please refrain from calling it "Order Ticket Position"
- The 1st Position within the Pool is always Zero

 

ubzen,

@WhooDoo22:if OrdersTotal() returns 10, the first position is 1 and last position 10. = false.

I believe I was close in stating 1 as the first position and 10 as last position because I thought it was similar to value representation of OrdersTotal().

One as first and zero as first is very close. Ten as last and nine as last is very close. The error was within value representation.


- The 1st Position=0 && The Last Position = OrderTotal - 1

I understand the 1st Position value is represented as zero because Order position number values are represented similar to array (example: 0,1,2,3,4,etc.).

I do not understand why the Last Position equals OrdersTotal() -1. Is this because OrdersTotal() function deals with current orders only so any orders in history are considered minus one?


- Why do you keep saying "Order Ticket Position"

Because this "Order ticket" represents the ticket in the market and "Order ticket Position" represents the ticket's position.


- It's either "Order Ticket" or "Order Position"

I believe it best to call "Order Ticket" "Order ticket number" and call "Order Position" "Order position number". It is important to be descriptive as the two can cause confusion if the difference is not understood.


- The 1st Position within the Pool is always Zero

If this is indeed the case then this goes back to value representation. The value representation is similar to an array (example: 0,1,2,3,4,etc.).


Thank you.

 

@WhooDoo22: I do not understand why the Last Position equals OrdersTotal() -1.

Its like you have Runners on a Track. The Lanes are illustrated below.

|0|1|2|3|4|5|6|7|8|9|

Note, the Lanes are designated 0->9 because that's how the guy who painted the tracks felt like numbering them. [Oh-lord, please don't ask me why he painted it that way :) ].

Anyways the track is full of Runners for this event. These Runners all have Numbers on their Backs. If you've ever watched a Race then you know what I'm talking about. But these Runners choose their own personal numbers. Could be the first guy thinks 7 is his lucky number and puts that on his uniform. And the Last guys late-father used to have 23 on his back, so to honor his daddies memory, he's wearing Number_23 today. Anyways the Runners line up as follows.

|7|93|41|68|17|45|22|6|16|23|

Someone just asked a girl named OrdersTotal how many Runners are there in the race. OrdersTotal responded Ten[10] (because she's so smart).

Someone just asked a girl named "i" aka "index" for the position of the 1st Runner. To which she promptly responds 0 (because she's so smart). She's also asked for the position of the Last Runner and she responds Nine[9] looking at the track above.

Someone just asked a girl named OrderTicket what is the Runner_Number in the 1st_Position. And she responds 7. (because she's so smart). And for Runner_Number in Last_Position she responds 23 "because he's honoring his daddy today".

Now which runner will win the race, I'll save that scenario for another day. However I hope my case-study help you understand.

If you look at the position number, they're all OFF by 1. Simply because the painter decided to start his count from Zero. If he started his count from 1 then yes it'll be 1>10. At such every number can be represented relative to OrdersTotal. Even the 1st_Position can be represented as (OrdersTotal - OrdersTotal) which yields 0.

 

ubzen,

What a fascinating illustration you present to me. Thank you very much for taking time to express it in such detail!

As for which runner will win the race, typically the runner located in the innermost lane of a track assuming all runners sprint at the same rate of speed. I don't know if this correlates with your illustration but if it does, it might possibly be (index zero or index nine) or (runner seven or runner twenty three).

Thank you.

 
You're Welcome.
 
RaptorUK:
The fist position in the pool . . .  just like an array,  the first element is at position 0,  the second is at 1, the third at 2, etc.  

What I find strange is that you try and use this function yet not know how to use it . . .  haven't you looked at other code and seen a loop counting down from OrdersTotal() - 1 ?  why do you think the -1 is there ?

You read this post . . .  so you knew that the first position in the pool was 0,  yet now you say it is 1,  I'm confused,  why would you say such a thing ?
 

Simon,

Honestly Simon, the day has been so long and I feel a bit confused as well regarding certain things. ;) Maybe its best for me to acquire a necessary meal, good drink and sleep to power up for the coming day so as to once again possess clear reasoning for discussion. I am satisfied with this days progress.

Thank you.

 
WhooDoo22:

Simon,

Honestly Simon, the day has been so long and I feel a bit confused as well regarding certain things. ;) Maybe its best for me to acquire a necessary meal, good drink and sleep to power up for the coming day so as to once again possess clear reasoning for discussion. I am satisfied with this days progress.

Thank you.

Good idea,  then get to work on the fundamentals.
 

Simon,

You read this post . . .  so you knew that the first position in the pool was 0,  yet now you say it is 1,  I'm confused,  why would you say such a thing ?

I understand value representation for an order pool. Ya' know what the big clue is to understanding the value representation for an order pool? I'll tell you anyway :) index. Isn't index considered the same as...

array: 0,1,2,3,etc. Each value to be filled with a single/combination of digits.

and...

shift values: 0,1,2,3,etc. Each value, a shift of the current or previous time frame tick (example: M5 time-frame. Current index for M5 time-frame is zero (0). The very last or most recent shift for M5 time-frame is indexed as one (1) or its location is index 1.)


There is multiple MQL4 code representing values 0,1,2,3,etc. The "magic" word to notice is index.

So ;), lets have a peek in the MetaEditor dictionary and see what it offers us for its definition of the OrderSelect() function?

bool OrderSelect( int index, int select, int pool=MODE_TRADES)

Huh ;), low and behold there is an index, just as expected. This should sweep aside any obscurities from thought to the value representation of the first value contained within the OrderSelect() function. :)

Wait, it is also important to understand that index applies only to OrderSelect() function ONLY if the function is locating orders in an order pool. That should be it for that.


With that written, I rewind settings to the problem I arrived at not so long ago.

invalid ticket error

The above snapshot error is the current issue needing to be addressed. What advice do you recommend to solve this issue?

Thank you.

Reason: