How do I modify the magic number on an order?

 

I've been reading on magic numbers and understand that they are assigned when the order is placed.

I would like to select orders, have them perform a function if the magic number originally assigned is matched and then change the magic number on the order so that I know that it's done that function and doesn't repeat it when it's looked at another time.

Looking at the OrderModify() I don't see any way to modify the magic number..

please help.

 

This is not an answer to your question, but it may be an answer to your problem: unless you have many, many orders open, or unless the function takes an awful lot of time to perform its duty, it shouldn't make a noticeable difference to perform the function on all open orders, even if some of them have already gone through that function before.

If the function is such that you don't want it to treat orders that have already been treated, well, I don't know how to/if it is possible to change magic/ticket numbers...

So, a work around would be to store in an array the numbers of the orders that been treated. When looping through the open orders, you would check their numbers against the numbers that are in the array, before sending them-or not- to the function. (Of course, this test can be done within the function as well).

 

Aaragorn

It is true that the Magic number is assigned when the order is place and cannot be modified after ward. You are in error with beleiving that the number is not under your control as the programer can utilize any number or number sequence to identify an oder. This must be done in with the way your EA is writen. The Order Comment field is also available to label orders but this to must be done at time of order placement and can not be changed.

The CockeyedCowboy

Aaragorn:
I've been reading on magic numbers and understand that they are assigned when the order is placed.

I would like to select orders, have them perform a function if the magic number originally assigned is matched and then change the magic number on the order so that I know that it's done that function and doesn't repeat it when it's looked at another time.

Looking at the OrderModify() I don't see any way to modify the magic number..

please help.
 

thank you both for your replies...

I'm just a novice programmer, I don't know if I have the savvy to pull off the array thing. It sounds like it could work if each order can be given a unique number.

the goal is to distinguish each order so that I can limit each order to using the function only one time on the first instance that the conditions are met. If the magic number and comment fields cannot be changed after the order is placed then those won't help me. I wonder if the arrow color could be used as a distinguishing tool? like ask, send new orders with a specific arrow color. Then when the function looks at the orders ask if the arrow color matches that. If color matches then do function and change color??? The arrow color IS available on both the send order and the modify order.

How would I test the color on the selected order, the compiler doesn't like these...

&& "dodgerblue" == color && "dodgerblue" == arrow_color

the first one it says 'variable expected'

the second one it says 'variable not defined'

i don't see an "Orderarrow_color" anywhere

will this get it?

&& "DodgerBlue" == OBJPROP_COLOR

the compiler says..

'==' - different types in comparison

I think I have another way to accomplish my goal...with variables I know I can retrieve and compare.

 

Again, not an answer, just a remark or 2:

The ticket number is unique to each order, but you can't change it.

I've never played with that color_arrow thing. Well, try it and see what happens!

MT4 is case sensitive, so "DodgerBlue" is recognized but "dodgerblue" isn't. (See how DodgerBlue appears in blue fonts in MetaEditor, whereas dodgerblue appears in black fonts).

I haven't used Objects that much, but I believe that OBJPROP_XXX can be used with Objects only.

If you're a novice programmer but feel you're running into the limits of the language already (and mql is indeed very limited), there may be easier ways to solve the problem. In other words, are you really sure you need to modify an Order variable to "limit each order to using the function only one time on the first instance that the conditions are met."?

Anyway, I salute your perseverance!

 
Aaragorn:
I'm just a novice programmer, I don't know if I have the savvy to pull off the array thing. It sounds like it could work if each order can be given a unique number.

It could be done that way: declare an array outside of functions (ie as a global variable):

int treated[20]=0.0; //(works for a max of 21 orders)[/CODE]

In the start function, where you loop through tickets:

(note: it s better to loop from last ticket number to first; see the attachments)

[CODE]

bool forget_it = false;

//...

for (int ticket=GetLastTicket("",-1,-1); ticket!=0; ticket=GetPreviousTicket())

{

OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);

if(condition met to send the order to the function My_function())

{

//sets forget_it to true if the order has already been sent to My_function()

for(j=0;j<20;j++)

if(ticket == treated[j]) forget_it = true;

//sends the order to My_function if it hasn't been sent yet

if(!forget_it)

{

forget_it = false; //resets forget_it

My_function(ticket);

//puts the ticket number into the array, so the order won't be sent to My_function a second time.

j=0;

while(treated[j]!=0) j++;

treated[j]=ticket;

}//end if(!forget_it)

} //end if(condition met to send the order to the function My_function())

} //end for (int ticket=GetLastTicket(symbol,-1,-1); ticket!=0; ticket=GetPreviousTicket())

There must be much smarter ways to do it, but this should work.

Also, for future (!) problems with orders, check the post by cockeyedcowboy:

https://www.mql5.com/en/forum/general

Files:
 
 

this is what I'm attempting to do...

https://www.mql5.com/en/forum/general

Reason: