OrderModify() question - page 3

 

Simon,

I'm trying to think how I would go about doing this, but nothing is coming up. I am scouring the dictionary in MetaEditor for possible routes. I am considering the use of the OrderSymbol() and OrderSelect() functions in concert. If you are giving me an option for a hint, obviously I'll take it. What is the hint? ;) I consider this more of a discussion than a challenge. If you consider this a challenge, I will agree to no hints. I have full confidence in my ability.

Thank you.

 

Why would you use MarketInfo() ?  to tell you what ?

 
Before you can code this you need to figure out how to do it and then be able to express that using simple language, not code.  


The code needed to meet this requirement contains many aspects of what you needed to do with the code you put in the Code Base.


It's bed time for me now . . .  so here is a hint to get you started,  you have multiple orders,  so you need to loop through them all to find the right one . . . or maybe more than one, cover as many options as you can see.

If you can't find a way let me know and I'll come up with what I think is a solution and post it . . .  then you can read it, understand it and tear it apart and ask me to justify any part of it that you think is wrong or not needed. 

Either way I am convinced you will learn in the process.

 

Simon,

Richard Bhauer sent me a revised version of what I posted earlier. It is definitely NOT my coding style preference, but I think its impressive. I thought I would share it with you to see if this code has any connection to a method you are promoting for order selecting and order closing. Thanks again to Richard. Also, a reason I thought I would try the OrderSymbol() was because I have written EAs using multiple ordersends of OrderSend("GBPUSD"...); or any currency pair. I assumed, I could simply attempt a similar process to close orders. Apparently, the work of selecting the order (in order to close it) is done within the OrderSelect() function. In the previous post, you mentioned as a hint, to try running a loop to locate the correct ticket number (I am guessing that the loop is run first and when the ticket is found, drop down to the next code block containing firstly the OrderSelect() function. Inside the OrderSelect() function would be the variable used in the previous code block of the loop to find the correct ticket number. The OrderSelect() function would use the variable to select the ticket. Once the ticket is selected, everything else is pretty straight forward. I'll read your response in the morning.

Thank you.

Files:
 
WhooDoo22:

 Apparently, the work of selecting the order (in order to close it) is done within the OrderSelect() function. 

Read through the Documentation for the following functions,  OrderTicket(), OrderLots(), OrderClosePrice(), OrderProfit(), OrderType(), OrderTakeProfit(), OrderSymbol(), OrderStopLoss(), OrderOpenTime(),  OrderOpenPrice()  they all have the following stated:  Note: The order must be previously selected by the OrderSelect() function.

OrderClose() does not have this statement because you pass the ticket number to OrderClose() as the first parameter   . . .  with all the functions listed above you do not,  so to use them you firstly have to select the order you are interested in,  that is the job of OrderSelect() . . .  then you can find it's position size with OrderLots()  or it's open price with OrderOpenPrice(),  but first it has to be selected.  


You must grasp this concept and understand it  . . . .
 

WhooDoo22:

In the previous post, you mentioned as a hint, to try running a loop to locate the correct ticket number (I am guessing that the loop is run first and when the ticket is found, drop down to the next code block containing firstly the OrderSelect() function. Inside the OrderSelect() function would be the variable used in the previous code block of the loop to find the correct ticket number. 

How will you find the correct ticket number from inside a loop ?  you don't know which ticket number is the correct one . .   what information do you have that you can use ?
 

Simon,

The following functions,  OrderTicket(), OrderLots(), OrderClosePrice(), OrderProfit(), OrderType(), OrderTakeProfit(), OrderSymbol(), OrderStopLoss(), OrderOpenTime(),  OrderOpenPrice() must be previously selected by the OrderSelect() function.

OrderClose() function is not required to be previously selected by the OrderSelect() function because the OrderClose() function passes the ticket number as the first parameter.

The purpose of OrderSelect() is to select an order.

Concepts understood, I'll review documentation.

How will you find..

RE: Still workin' this out.

Thank you

 

Simon,

It seems you keep pointing out "ticket number". I understand this. Here's the thing though, I am aware of only two ways to isolate tickets using OrderSelect() function. I can use the "Order pool" way, where there is no specific ticket number variable OR I can use the other way, where I can use a specific ticket variable name "ticket", "bababab22", "lambchops", anything, to isolate the ticket. I do believe using the "Order pool" way is most practical, so I am considering use of this function in this fashion. I like it.


Also, I skimmed through Robert's revision and noticed when he closed orders, he simply used the OrderSelect() function, (the one where you select from a pool of orders) and the only "if" condition used besides the obvious signal close was lot size and if order was buy/sell. That was it. I Like it, but this is not currently the task. In this task, yeah sure, I could type the same thing, but nothing would be learned. What is difficult currently is How can I learn what it is you wish to teach, if I do not know what you are trying to teach me. I believe if you could be more direct with your thoughts, I could grasp what it is you wish to share with greater speed. I'll try to be more understanding.

Thank you.

 
WhooDoo22:

Simon,

It seems you keep pointing out "ticket number". I understand this. Here's the thing though, I am aware of only two ways to isolate tickets using OrderSelect() function. I can use the "Order pool" way, where there is no specific ticket number variable OR I can use the other way, where I can use a specific ticket variable name "ticket", "bababab22", "lambchops", anything, to isolate the ticket. I do believe using the "Order pool" way is most practical, so I am considering use of this function in this fashion. I like it.

In this case you cannot store the ticket number in a variable as the orders are placed manually, so the code does not know any ticket numbers until it discovers them,  so you can only use the first option using a loop and OrderSelect().

Saving ticket numbers is a big inconvenience and should be avoided unless you must do it,  meaning there is no possible way to avoid it . . .  why ? because your code must be able to recover from a MT4 restart, so that means saving the info about the tickets to files and ideally copying the files to a 2nd PC for additional backup cover.   Then when the code restarts it has to read the file get the ticket numbers and try and pick up from where it left off  . . .   this kind of complexity is not needed by most people,  but often they think saving ticket numbers is the simpler option . . .    and they don't really need to save the info to files, etc, etc . . .  then when it all goes wrong they wish they had.  

OK,  I coded my version of the code to meet my requirement,  I added some checks to detect multiple USDJPY orders and modify and close all USDJPY orders . . . here are some screen grabs to show how the final version went.   


The Orders I placed manually . . .

All Orders

 

The USDJPYi orders my code modified (note the TP & SL) and closed.,  and also the Ticket number.   Also note the mix of Buy and Sell orders.

Closed USDJPYi Orders 

 The remaining orders . . .

Remaining Orders 

 

Simon,

In this case you cannot store the ticket number in a variable...

RE: So you are going with the "order pool" route for this example, correct?

// order pool example

if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)){

Saving ticket numbers is a big inconvenience...

RE: Agreed.

saving the info about the tickets to files and ideally copying the files to a 2nd PC for additional backup cover...

RE: Yes, but saving info about tickets to files, is separate group of code blocks for my situation currently. I wouldn't start coding this until the fundamentals are written.

I coded my version of the code to meet my requirement...

RE: Yeah, I can see that. It seems well. :)


After I complete this task, I will continue on with volume II. It's not going to write itself. ;)

Thank you.

 
WhooDoo22:

Simon,

In this case you cannot store the ticket number in a variable...

RE: So you are going with the "order pool" route for this example, correct?


Is there another option ?
 

Simon,

Nope, not that I know of. There seems to be only two options and this option seems best for volume II. Also, it seems less complicated, and I don't mind that one bit. ;)

So, back to this task, I understand you used the order pool method for selecting the order on usdjpy pair, but what condition did you use to isolate the order on usdjpy?

Thank you.

Reason: