need help with close out trades.

 
I try to writes a beginner EA  and I wish the EA able to close out the opened order after 6 hours, if any one can help me out I very appreciated, Thanks.
 
jaypra:
I try to writes a beginner EA  and I wish the EA able to close out the opened order after 6 hours, if any one can help me out I very appreciated, Thanks.
What have you tried ?
 
jaypra:
I try to writes a beginner EA  and I wish the EA able to close out the opened order after 6 hours, if any one can help me out I very appreciated, Thanks.

What is your concrete issue???. Put your attempt and maybe anybody help you. Otherwise, you could consider this section:

https://www.mql5.com/en/job

Regards.

Freelance service at MQL5.com
Freelance service at MQL5.com
  • www.mql5.com
Orders for the development of automated trading programs
 
jaypra I wish

learn to code it, or pay (Freelance) someone to code it.
We're not going to code it for you.
We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
 
Alain Verleyen:
What have you tried ?

This is what I tried;

//+------------------------------------------------------------------+
//| Check for close profits conditions                               |
//+------------------------------------------------------------------+
void Trade_Close()
  {
  int res;
   int CloseHour=6;
   int CloseMM=30;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
      //---- check order type
      if(OrderType()==OP_BUY)//exit buy.
        {      
          if(OrderOpenTime()>TimeCurrent() && Hour()>CloseHour && Minute()>CloseMM)
           res=OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)//exit sell.
        {      
          if(OrderOpenTime()<TimeCurrent() && Hour()>CloseHour && Minute()>CloseMM)
           res=OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         break;
        }
     }
  }
 
for(int i=0;i<OrdersTotal();i++) i=OrdersTotal()-1;i>=0;i--

Always count down when working with orders, mandatory if you want to close.

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break; continue;

No need to break, continue.

if(OrderType()==OP_BUY)//exit buy.

Completely unneeded. Use OrderClosePrice() instead of Bid/Ask, it will be the right close price.

if(OrderOpenTime()>TimeCurrent() && Hour()>CloseHour && Minute()>CloseMM)

Here I am not sure what you want to do, but this condition will never be true. An order can't be opened after the current time, unless you found a way to travel in time. (Nota: please gurus don't start to argue about that :-D).

         break;
Why do you want to break there ?
 
Alain Verleyen:
for(int i=0;i<OrdersTotal();i++) i=OrdersTotal()-1;i>=0;i--

Always count down when working with orders, mandatory if you want to close.

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break; continue;

No need to break, continue.

if(OrderType()==OP_BUY)//exit buy.

Completely unneeded. Use OrderClosePrice() instead of Bid/Ask, it will be the right close price.

if(OrderOpenTime()>TimeCurrent() && Hour()>CloseHour && Minute()>CloseMM)

Here I am not sure what you want to do, but this condition will never be true. An order can't be opened after the current time, unless you found a way to travel in time. (Nota: please gurus don't start to argue about that :-D).

         break;
Why do you want to break there ?
Alain Verleyen:
for(int i=0;i<OrdersTotal();i++) i=OrdersTotal()-1;i>=0;i--

Always count down when working with orders, mandatory if you want to close.

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break; continue;

No need to break, continue.

if(OrderType()==OP_BUY)//exit buy.

Completely unneeded. Use OrderClosePrice() instead of Bid/Ask, it will be the right close price.

if(OrderOpenTime()>TimeCurrent() && Hour()>CloseHour && Minute()>CloseMM)

Here I am not sure what you want to do, but this condition will never be true. An order can't be opened after the current time, unless you found a way to travel in time. (Nota: please gurus don't start to argue about that :-D).

         break;
Why do you want to break there ?
I see what you mean, Thanks
 
jaypra:
I see what you mean, Thanks
Yes, twice.
Reason: