open() -> select() -> modify() -> all Trading Functions return what order opened with. WHY ?

 

Your help appreciated,

unless I have missed in docs, I understood that successful OrderSelect(ticket,..) meant that Trading Functions could be called eg, OrderStopLoss() or OrderTakeProfit()

but, if after OrderSelect(ticket,..) I issue OrderModify(ticket,...,newSL||newTP,...) and then eg, Print("SL=",OrderStopLoss()); the SL value printed is the value at time of OrderSend() and not the SL value given in OrderModify()

IF OrderSelect(ticket,..) is effectively reissued on same ticket# and then Print("SL=",OrderStopLoss()); the SL value printed is the new value given in OrderModify()

?? why is this ?? - the ticket# is same, but it appears that server/terminal needs a kick to get it to map the latest values which were given in OrderModify()


I understand the need to scan opened orders trade pool with magic# so can get new ticket when partial-take-profit OrderClose(ticket, part-lots,...) issued.

But not understand what's going on over this OrderModify() event.

Thank you

 

Hmmm...


I agree... I guess OrderSelect() fills a buffer for queries on that ticket with the current values from the ticket at that moment...

Then, that "snapshot" is not updated until a new OrderSelect is issued.

Here is a test script:

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   int ticket;
   int result;
   ticket = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 0, 0, 0, "", 50, 0, Red);
   Sleep(1000);
   result = OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
   if(result == true)  Print("OrderSelect Success");
   if(result == false) Print("OrderSelect Fail");
   Sleep(1000);
   Print("StopLoss = ", OrderStopLoss());
   result = OrderModify(ticket, OrderOpenPrice(), Ask-50*Point, 0, 0, Blue);
   if(result == true)  Print("OrderModify Success");
   if(result == false) Print("OrderModify Fail");
   Sleep(1000);
   Print("StopLoss Before re-select = ", OrderStopLoss());
   result = OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
   if(result == true)  Print("OrderSelect Success");
   if(result == false) Print("OrderSelect Fail");
   Sleep(1000);
   Print("StopLoss After re-Select = ", OrderStopLoss());
   result = OrderClose(ticket, 0.1, Bid, 0, Lime);
   if(result == true)  Print("OrderClose Success");
   if(result == false) Print("OrderClose Fail");
   return(0);
  }

And Output:

15:14:21 Phy__Test_OrderSelect AUDUSD,Daily: loaded successfully
15:14:21 Phy__Test_OrderSelect AUDUSD,Daily: open #4050618 buy 0.10 AUDUSD at 0.9189 ok
15:14:22 Phy__Test_OrderSelect AUDUSD,Daily: OrderSelect Success
15:14:23 Phy__Test_OrderSelect AUDUSD,Daily: StopLoss = 0
15:14:24 Phy__Test_OrderSelect AUDUSD,Daily: modify #4050618 buy 0.10 AUDUSD at 0.9189 sl: 0.9139 tp: 0.0000 ok
15:14:24 Phy__Test_OrderSelect AUDUSD,Daily: OrderModify Success
15:14:25 Phy__Test_OrderSelect AUDUSD,Daily: StopLoss Before re-select = 0
15:14:25 Phy__Test_OrderSelect AUDUSD,Daily: OrderSelect Success
15:14:26 Phy__Test_OrderSelect AUDUSD,Daily: StopLoss After re-Select = 0.9139
15:14:27 Phy__Test_OrderSelect AUDUSD,Daily: close #4050618 buy 0.10 AUDUSD at 0.9189 sl: 0.9139 at price 0.9186
15:14:27 Phy__Test_OrderSelect AUDUSD,Daily: OrderClose Success
 

Thank for input Phy - a great visual example. The terminal's 'ok' message accurately shows change - thank goodness for small mercies!

Is this a bug? reason I ask is most likely many use trade functions after a modify() and for sure this would be dodgy. Then again, would have thought this would have been noticed by active EA traders ages ago. (unless the old adage: there are many bold EA traders but few bold and old EA traders!!!)

Phy - if you reading this, a quicky for you: when do modify() should one always use non-zero actuals in places not changing?

: order was opened : #6751712 buy 0.01 GBPUSD at 1.9636 sl: 1.9611 tp: 1.9661
: modify order #6751712 buy 0.01 GBPUSD at 1.9636 sl: 1.9611 tp: 1.9661 -> sl: 1.9616 tp: 0.0000
: order #6751712 buy 0.01 GBPUSD at 1.9636 was modified -> sl: 1.9616 tp: 0.0000
: modify order #6751712 buy 0.01 GBPUSD at 1.9636 sl: 1.9616 tp: 0.0000 -> sl: 0.0000 tp: 1.9671
: order #6751712 buy 0.01 GBPUSD at 1.9636 was modified -> sl: 0.0000 tp: 1.9671
Seems like should use orderstoploss(), ordertakeprofit() in the modify()
yes?
Thanking you Phy
 
Seems like should use orderstoploss(), ordertakeprofit() in the modify()

Yes, that's what I do.

In the beginning I would try to keep variables or arrays updated with those values, decided it was a waste of effort unless there
was some other need for that.

so, when changing stop loss..

bool OrderModify ( int ticket, double price, double stoploss, double takeprofit, datetime expiration, color arrow_color=CLR_NONE)

becomes

OrderModify(OrderTicket(), OrderOpenPrice(), VARIABLE_SL, OrderTakeProfit(), OrderExpiration(), SomeColor)


Is it a bug?

I used to work for NEC, the Japanese would answer such trouble reports with "This is the way of design"

 

Excellent! That's the icing on the cake for me - shall go away and plod on with this VIP knowledge - thanks.

I used to work for NEC, the Japanese would answer such trouble reports with "This is the way of design"

Well... this seems suitably obscure and Zen like... but from a binary outlook - seems somewhat hopeless! (imho of course)


Thanks again Phy, important answers are sometimes small in presentation but powerful in effect...

yours are such ;)

 

I have taken the liberty of modifying my copy of ed's docs (line.9660,..) C:\Program Files\MetaTrader - Alpari UK\languages\metaeditor.xml (I added bottom two lines)**

I so much do not want to make error of NOT reselecting after OrderModify() call - think I'll embed in helper function and document well ...

Is total kludge and will get lost next update - but for now... keeps me on OK path!


Modification of characteristics for the previously opened position or pending orders. If the function succeeds, the returned value will be TRUE. If the function fails, the returned value will be FALSE. To get the detailed error information, call GetLastError() function.
Notes: Open price and expiration time can be changed only for pending orders.
If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated.
Pending order expiration time can be disabled in some trade servers. In this case, when a non-zero value is specified in the expiration parameter, the error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated.
Note: Future calls to Trading Functions must be preceded by the OrderSelect() function.
IMPORTANT! Failure to 'reselect' order causes Trading Functions to return pre-OrderModify() requested order information.


**

<br/>
Note: Future calls to Trading Functions must be preceded by the <a href="help://trading_OrderSelect">OrderSelect()</a> function.
<br/><b>IMPORTANT!</b> Failure to 'reselect' order causes Trading Functions to return pre-OrderModify() requested order information.


 
Hence to solve this error I need to
1. use a "for loop" to select the current order
2. once I get the current order, I will then get the current ticket number.
3. Use the current ticket number to close my open positions.

something like this:

for(int x=OrdersTotal()-1;x>=0;x--)
{
OrderSelect(x,SELECT_BY_POS); // select current order
if order select (... ) == true then CurrentTicketNumber =OrderTicket(); // get current ticket number*/
}

then later in the code I will close the order like this

OrderClose( CurrentTicketNumber, CurrLot, NormalizeDouble(Ask, Digits), Slippage, DimGray);


If you have time can you please fix this bit of code so it works... Please

 
Dear Trader, can you please help with this bit of my code
As my trade progress.. the stop is modified the ticket number is changed. Hence when my code tried to close the order I get Error..
OrderModify error 1


Hence to solve this error I need to
1. use a "for loop" to select the current order
2. once I get the current order, I will then get the current ticket number.
3. Use the current ticket number to close my open positions.

something like this:

for(int x=OrdersTotal()-1;x>=0;x--)
{
OrderSelect(x,SELECT_BY_POS); // select current order
if order select (... ) == true then CurrentTicketNumber =OrderTicket(); // get current ticket number*/
}

then later in the code I will close the order like this

OrderClose( CurrentTicketNumber, CurrLot, NormalizeDouble(Ask, Digits), Slippage, DimGray);


If you have time can you please fix this bit of code so it works... Please

 
Modifying the stop does NOT change the ticket number. Modifying the lot size DOES.