You should in cycle find the latest one (based on OrderOpenTime()) for each type, and then get its Ticket Number.
for each type:
if(OrderOpenTime()>last_date)
{
last=OrderMagicNumber();
last_date=OrderOpenTime();
}
return last;
You should in cycle find the latest one (based on OrderOpenTime()) for each type, and then get its Ticket Number.
for each type:
if(OrderOpenTime()>last_date)
{
last=OrderMagicNumber();
last_date=OrderOpenTime();
}
return last;
Don't forget to OrderSelect() first.
{
datetime last_time = 0;
int ticket = -1;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS)) continue;
if(OrderSymbol() != _Symbol) continue; // optional
if(OrderMagicNumber() != magic) continue; // optional
if(OrderType() != order_type) continue;
datetime open_time = OrderOpenTime();
if(open_time > last_time)
{
ticket = OrderTicket();
last_time = open_time;
}
}
return(OrderSelect(ticket,SELECT_BY_TICKET));
}
Please use this function:
//| Check Last Trade function |
//+------------------------------------------------------------------+
int CheckLastTrade(int Type)
{
datetime OpenTime = 0;
int Ticket = 0;
for( int cnt = OrdersTotal()-1; cnt >= 0; cnt-- )
if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
if ( OrderType() == Type )
if ( OrderOpenTime() > OpenTime )
Ticket = OrderTicket();
return (Ticket);
}
If you want to check the last OP_BUY, you can use :
The result is the ticket number of last buy
Hi , all i come back again , when i use this code
int CheckLastTrade()
{
datetime OpenTime = 0;
int Ticket = 0;
for( int cnt = OrdersTotal()-1; cnt >= 0; cnt-- )
if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
if ( OrderType() == OP_SELLSTOP )
if ( OrderOpenTime() > OpenTime )
Ticket = OrderTicket();Alert ("Ticket=",Ticket);
return (Ticket);
The result gives me the ticket n°89565499,whereas I want to have the ticket N°89565547 see more on the pics
thank for your help
-
Play videoPlease edit your post.
For large amounts of code, attach it
Don't post a link to or attach a image, just insert the image
if ( OrderOpenTime() > OpenTime )
Where do you update OpenTime so that you find the latest one?
int CheckLastTrade() { datetime OpenTime = 0; int Ticket = 0; for( int cnt = OrdersTotal()-1; cnt >= 0; cnt-- ) if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES )) if ( OrderType() == OP_SELLSTOP ) if ( OrderOpenTime() > OpenTime ) Ticket = OrderTicket();Alert ("Ticket=",Ticket); return (Ticket);
my orders
i used Alert to see the résult
But i wanted use the ticket number 89565547(the last OP_SELLSTOP) for the part of the code) ( i wish that it s clear for you
void deletingPendingOrdersSell() {if (Bid-LastPenedingOrderSellStop<1000*Point){ // the LastPenedingOrderSellStop must be the ticket n°89565547, the number 1000 is only for the tests when the code will be good then i ll change it // Iterate orders for(int i = OrdersTotal()-1; i >= 0; i--) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); Type = OrderType(); if(OrderSymbol() == Symbol()) { if(Type == OP_BUYSTOP || Type == OP_BUYLIMIT ) if(Type == OP_SELLLIMIT || Type == OP_SELLSTOP|| Type == OP_BUYSTOP||Type == OP_BUYLIMIT ) { if(!OrderDelete(OrderTicket())) Print(ShortName +" (OrderDelete Error) "+ ErrorDescription(GetLastError())); } } } }
Hi,I am learning the trading, and I started in expert advisors programming. Thanks for the tips I would apply them.i use this code
my orders
i used Alert to see the résult
But i wanted use the ticket number 89565547(the last OP_SELLSTOP) for the part of the code) ( i wish that it s clear for you
How do you open each OP_SELLSTOP order? different magic number?
better to assign different magic number, as it is easier to select from order pool.
void DeletePendingOrders(int magic, int type) { for(int order = 0; order <= OrdersTotal() - 1; order++) { bool select = OrderSelect(order,SELECT_BY_POS); if(select && OrderMagicNumber()==magic && OrderType()==type) { bool Deleted = OrderDelete(OrderTicket(),clrRed); if(Deleted) { order--; Print("Order # ", OrderTicket(), " deleted"); } } } }
thank for your reply , as i told you im not a programmer , and i try to make my EA , and a good strategy .At this moment work with a magic number is not important as my code is not correct , but later it will be an obligation .your code is good but my probleme is the condition, to be more simple i need to call the procedure DeletePendingOrders(int magic, int type) only if (Bid-the last OP_SELLSTOP>140*Point)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
My questions are how to select the last OP_BUY, the last OP_SELL, the last OP_BUYSTOP and the last OP_SELLSTOP
Thank for your futures replies
Hurryc