Time Based Order Close

 

I'm a week in so I'm really green with coding. Especially since I have no programming background. Below is section of code I wrote to close an open order at a specific time. Although it compiles fine the orders stay open. I hoped I could get some pointers. I've only got OP_BUY in the section below but the plan is to have OP_SELL as well so it closes all open trades at NY close.

I'm sure I'm missing something simple as that seems to normally be the case hehe.

if(Hour()==EA_Deactivate)
   {for (int i=OrdersTotal()-1; i>=0; i--) {
                if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
                        if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic) && (OrderType()==OP_BUY)) {
                                OrderClose(OrderTicket(),Lots,Ask,30,Green);
            }             
         }
      }
        

Cheers,

Dud

 
OrderClose(OrderTicket(),Lots,Ask,30,Green);
  1. What are Function return values ? How do I use them ? - MQL4 forum Find out WHY.
  2. Lots -> OrderLots()
  3. Ask -> OrderClosePrice() Don't need to check order type
  4. 30 - 4/5 digit brokers Problems with a calculation - MQL4 forum