OrderModify() question - page 2

 
WhooDoo22:

Ah-ha! I switched the ticket number 0 to 1 and everything worked like clockwork. Yes, I was wrong William... The OrderSelect() function was an issue. Obviously the OrderSelect() function must select a ticket. If the ticket number is 0, what ticket will the EA select? :O "?". Thank you both for your assistance.

Thank you.

The ticket number will   NEVER  be 0 . . .   it's not a valid ticket number.


Pleas refer to this thread:  https://www.mql5.com/en/forum/142545
 

Simon, I understand 0 is not a valid ticket number BECAUSE 0 means there are no tickets to select. 1 represents a ticket AND the specific ticket number which OrderSelect() function is attempting to select.

I'll read the thread. Thank you for posting it.

Thank you.

 
WhooDoo22:

I understand 0 is not a valid ticket number BECAUSE 0 means there are no tickets to select. 1 represents a ticket AND the specific ticket number which OrderSelect() function is currently selecting. 

No,  that is not correct.  zero as a ticket number does not mean anything,  it is INVALID.  OrdersTotal() == 0  means there are no orders . . .  it is obvious you are mixing up the results from different functions and ticket numbers vs order positions


Don't do exactly what you did before . . . .  unless you want exactly the same outcome.   You can't assume you have the correct ticket number .. . .   you need to find it in the Order Pool and then select it . . . 

 

If you want to learn do this exercise:

 

  • open a new Demo account with any Broker
  • place a market order for 0.1 lots with no TP or SL
  • write some code that will find the correct ticket number for this order,  then use the ticket number to select the order,  then modify it so that it has a TP & SL and finally close it. 

 
RaptorUK:

No,  that is not correct.  zero as a ticket number does not mean anything,  it is INVALID.  OrdersTotal() == 0  means there are no orders . . .  it is obvious you are mixing up the results from different functions and ticket numbers 

If you want to learn do this exercise:

 

  • open a new Demo account with any Broker
  • place a market order for 0.1 lots with no TP or SL
  • write some code that will find the correct ticket number for this order,  then use the ticket number to select the order,  then modify it so that it has a TP & SL and finally close it. 


Did you try the exercise ?  show your code when you have done it . . .
 

Simon,

I'll code this project. It should be a piece a' cake. I've already done a bulk of the work. ;)

Yeah, I don't mind doing this exercise, seeing you have provided your consistent support.

Thank you.

 

Simon,

Done. I assumed you wanted the file in script format, so you could just drag and drop it on a chart, wait for the EA to crunch a few numbers, then watch it pull an order out of the market.

The differences between what I am currently building and this project is...

Currently building:

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)){

This project:

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

The reason I used "if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)){", is because I am dealing with an order pool and not a predefined specific ticket variable.

My current build for volume II uses predefined variables because I must select specific tickets to run volume II's strategy. This project was designed to simply close an order in the blink of an eye.

I actually had a couple question marks rise above my head as I coded the function execution containing Ask/Bid price. This is because, typically when sending/closing orders, I usually just type "Ask"/"Bid", but I realized I needed to define a variable which could be either Ask or Bid prices based on the condition if the order in the market was a sell OR buy order. Then, I just popped in the usual "if orders total is greater than zero", n' I was all set. That should prety much cover it.

Thank you.

Files:
 

OK,  it isn't what I intended but I should have been clearer with my requirement . . .   your code does not set a SL & TP . . .  but anyway let me revise my requirement . . .

Using the same Demo account . . .

 

  • place one market order for 0.1 lots with no TP or SL on GBPUSD,  one on USDJPY and one on EURUSD . . . forget the order in which you placed these Orders
  • without any consideration of the order in which the trades were placed and assuming no prior knowledge of the number of orders placed write some code that will find the correct ticket number for the order placed on USDJPY
  • print the ticket number to the log in the form  "Ticket number for USDJPY =   "
  • then use the ticket number to select the order,  then modify it so that it has a TP & SL and finally close it. 

 then when you are done please show your code and the line from the log showing the   ticket number

 

Simon,

Ah, sorry, I did not fully read your first instructions, and didn't code what you asked. Oh well, you added a new requirement list, so I'll get busy.

before I do, I will state what I am about to do...

1. Find ticket number of order placed on USDJPY.

2. Print ticket number to the log in the form "Ticket number for USDJPY = ".

3. Use ticket number to select the order AND modify the order so that it has a TP & SL and close it.

4. Show code and a line from log showing the ticket number.


With that said, I want to be clear we are on the same page.

Yeah, I can do 1. (obviously I can't use the "currency functions" to isolate the tickets right?)

Yeah, I can do 2.

3. Don't you mean, use OrderSelect() function to select the order AND modify it so it has a TP & SL and close it?

4. Obvioiusly, I'll show code ;)... a line from log showing ticket number ( what you could have asked for was a "visual snapshot" of the log showing the ticket number. No-matter)

Please post a response first before I begin task.


Thank you.

 
WhooDoo22:


With that said, I want to be clear we are on the same page.

Yeah, I can do 1. (obviously I can't use the "currency functions" to isolate the tickets right?)

Yeah, I can do 2.

3. Don't you mean, use OrderSelect() function to select the order AND modify it so it has a TP & SL and close it?

4. Obvioiusly, I'll show code ;)... a line from log showing ticket number ( what you could have asked for was a "visual snapshot" of the log showing the ticket number. No-matter)

You can use whatever functions you like as long as what you code meets the requirement . . .  and in doing that you don't breach what is given as a condition,  for example, "without any consideration of the order in which the trades were placed and assuming no prior knowledge of the number of orders placed" .  :-)
 
Hows it going ?  need any clarification or hints ?
Reason: