Select Automatically Order select

 
can i choose new order from function OrderSelect()? i think orderselect select by ticket, i want take value of order ticket automatically from my hitory. can i do it??
 
baguspramundana@gmail.com:
can i choose new order from function OrderSelect()? i think orderselect select by ticket, i want take value of order ticket automatically from my hitory. can i do it??

yes.

either select by ticket or select by magic number.
preferable, select by magic number, for many reasons.

 
Mohamad Zulhairi Baba:

yes.

either select by ticket or select by magic number.
preferable, select by magic number, for many reasons.

i want select new order, when it close, from history can i fetch taht new order? can you explain what must i write in metaeditor?


 
baguspramundana@gmail.com:

i want select new order, when it close, from history can i fetch taht new order? can you explain what must i write in metaeditor?


https://docs.mql4.com/trading/ordershistorytotal

 

OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false

how i can edit this function to select new order was i closed before??

 
baguspramundana@gmail.com:

OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false

how i can edit this function to select new order was i closed before??

I’m replying from mobile phone.
It should be like this;

for(i=0;i<OrderHistoryTotal()-1;i++)

{

If(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderTicket()==ticket)

{

  // do stuff here

}

}


Or



for(i=0;i<OrderHistoryTotal()-1;i++)

{

If(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderMagicNumber()==magic)

{

  // do stuff here

}

}


 
Mohamad Zulhairi Baba:
I’m replying from mobile phone.
It should be like this;

for(i=0;i<OrderHistoryTotal()-1;i++)

{

If(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderTicket()==ticket)

{

  // do stuff here

}

}


Or



for(i=0;i<OrderHistoryTotal()-1;i++)

{

If(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderMagicNumber()==magic)

{

  // do stuff here

}

}


what the value of variable ticket or variable magic ? 

 
Mohamad Zulhairi Baba:
I’m replying from mobile phone.
It should be like this;

for(i=0;i<OrderHistoryTotal()-1;i++)

{

If(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderTicket()==ticket)

{

  // do stuff here

}

}


Or



for(i=0;i<OrderHistoryTotal()-1;i++)

{

If(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderMagicNumber()==magic)

{

  // do stuff here

}

}


wow. i can fix it. thank you for your time.

 
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum