time based OrderClose Problem

 

I have problems w/ OrderClose function ... can someone help please?

the order should be closed on Monday at 00:01

OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
if((DayOfWeek()==1) && (Minute()>=1) )
{
if (OrderType()==OP_SELL)
{
OrderClose(ticket,Lot,MyBid,SlipPage,Green);
}
}
if((DayOfWeek()==1) && (Minute()>=15) )
{
if (OrderType()==OP_BUY)
{
OrderClose(ticket,Lot,MyAsk,SlipPage,Green);

}

}

....

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lot,MyAsk,SlipPage,MyBid+(Distance-SL)*Point,MyAsk+(Distance+TP)*Point,OrdComment,Magic,expire,Green);

....

ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot,MyBid,SlipPage,MyAsk-(Distance-SL)*Point,MyBid-(Distance+TP)*Point,OrdComment,Magic,expire,Green);




 

u forgot the main thing

for(int i = OrdersTotal() - 1; i >= 0; i--)
   {
   OrderSelect(i,..............
 

Please use this to post code . . . it makes it easier to read.



You didn't actually say what your problem was . . .

Did the pending Orders get activated by the time you are trying to Close them or are they still Pending . . . if they are still Pending you need to OrderDelete . . not OrderClose.

 
qjol:

u forgot the main thing

First line of his code . . .

OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
 

i'm so sorry ticket is a var that contains nothing according to ...

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lot,MyAsk,SlipPage,MyBid+(Distance-SL)*Point,MyAsk+(Distance+TP)*Point,OrdComment,Magic,expire,Green);

....

ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot,MyBid,SlipPage,MyAsk-(Distance-SL)*Point,MyBid-(Distance+TP)*Point,OrdComment,Magic,expire,Green);

& RaptorUK is right if it's a pending order u have to use OrderDelete()

 
if((DayOfWeek()==1) && (Minute()>=1) )
if it's monday between 00:01:00.00 and 24:59:59.99 close the order?
 

EA places 2 pending orders on friday @ 23:58, the second order expire and there is nothing to delete ... at the moment it does not work

the close will be ignored the current order should be exactly closed on Monday at 00:01

instead of TP for working the order i would like to use the CLOSE function, because of higher profit.

I'm a beginner programming mt4, can someone help me I do not know where to start.

OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
if((DayOfWeek()==1) && (Minute()>=1) )
{
if (OrderType()==OP_SELL)
{
OrderClose(ticket,Lot,MyBid,SlipPage,Green);
}
}
if((DayOfWeek()==1) && (Minute()>=15) )
{
if (OrderType()==OP_BUY)
{
OrderClose(ticket,Lot,MyAsk,SlipPage,Green);
}
}

if....

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lot,MyAsk,SlipPage,MyBid+(Distance-SL)*Point,MyAsk+(Distance+TP)*Point,OrdComment,Magic,expire,Green);

if....
ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot,MyBid,SlipPage,MyAsk-(Distance-SL)*Point,MyBid-(Distance+TP)*Point,OrdComment,Magic,expire,Green);
 

thanks guys, I have found a solution :-)

int i=0;

if((DayOfWeek()==1) && (Minute()>=1) )

 {

  for(i=0;i<OrdersTotal();i++)

   {

    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

    if(OrderType()==OP_BUY)

     {

      OrderClose(OrderTicket(),OrderLots(),Bid,SlipPage,Red);

     continue;

     }

    if(OrderType()==OP_SELL)

     {

      OrderClose(OrderTicket(),OrderLots(),Ask,SlipPage,Red);

     continue;

     }

   }



return(0);

}
 

Don't do this, it's bad practice . . .

for(i=0; i<OrdersTotal(); i++)

count down instead

for(i=OrdersTotal()-1; i>=0; i--)
 

thank you :-)

RaptorUK:

Don't do this, it's bad practice . . .

count down instead


Reason: