Select_By_Position

 

Hi All - I am having with the above code: for (i=0, i < TotalOrders()

First thing to note is that I am using trade context code with global variables to prevent problems with trade timings and trade context errors.

My code places a pending order or modifies an existing pending order immediately before checking and modifying for any non profit making trades by using SELECT_BY_POS as above.

When the non profit making trade is found the ticket number is correct as is the OrderOpenPrice() but the OrderStopLoss() retrieved does not match the what the ticket actually contains.

I remember having read somewhere that selecting by position can cause problems but cant remember where. I think it had something to do with the OrdersTotal() changing as orders are opened and closed.

Anyone able to help (sorry but I am unwilling to publish this part of my EA for obvious reasons

 

you remembered correctly. is many posts on this but, I find below which I do many years ago as to why not want go 0..total-1

please to cycle from top,...bot of pool list.

example follows IF go 0,1,2,totalorders-1 = bad news. want to go high/OrdersTotal()-1 --> low/0

hth

Orders:

A B C D

0 1 2 3

Loop starting with 0, count to 3 to close all orders.

Select and Close 0

Orders After Close:

B C D

0 1 2

Select and Close 1

Orders After Close:

B D

0 1

Select and Close 2

There is no 2 .

Select and Close 3

There is no 3 .

Loop end, orders B and D remain open.

 
fbj wrote >>

you remembered correctly. is many posts on this but, I find below which I do many years ago as to why not want go 0..total-1

please to cycle from top,...bot of pool list.

example follows IF go 0,1,2,totalorders-1 = bad news. want to go high/OrdersTotal()-1 --> low/0

hth

Orders:

A B C D

0 1 2 3

Loop starting with 0, count to 3 to close all orders.

Select and Close 0

Orders After Close:

B C D

0 1 2

Select and Close 1

Orders After Close:

B D

0 1

Select and Close 2

There is no 2 .

Select and Close 3

There is no 3 .

Loop end, orders B and D remain open.

Thats what I needed!! Thanks very much

Reason: