Download MetaTrader 5

Open position expiry

To add comments, please log in or register
Vantages
148
Vantages 2015.04.02 02:14 

Hello.

May I know if it's possible to add expiration through TIME any open positions to close at loss or at profit.

This is like open positions are time bound using seconds or hours. 

Thanks. 

Stuart Browne
5894
Stuart Browne 2015.04.02 02:29  
Vantages:

Hello.

May I know if it's possible to add expiration through TIME any open positions to close at loss or at profit.

This is like open positions are time bound using seconds or hours. 

Thanks. 

You can do it through code (OrderModify), but not manually through MT
Vantages
148
Vantages 2015.04.02 02:49  
Filter:
You can do it through code (OrderModify), but not manually through MT
Thanks. But, could you please give one specific example say if I have one open position that I only like to remain open for 60seconds and will not care either at loss or at profit. Sorry, currently I'm just using my mobile phone.
Stuart Browne
5894
Stuart Browne 2015.04.02 04:40  
Vantages:
Thanks. But, could you please give one specific example say if I have one open position that I only like to remain open for 60seconds and will not care either at loss or at profit. Sorry, currently I'm just using my mobile phone.
Sorry mate, I misunderstood what you were asking. In that case, you will need to check the order either in OnTick or an event timer and if it reached the 60 seconds, close it with OrderClose() 
Jose Miguel Soriano
4984
Jose Miguel Soriano 2015.04.03 17:45  

You can set expiration date on a pending order, but not in an open position.

The closing time must be in code. For example, with the function ...  

//----------------------------------- TIEMPO NETO POSICIÓN ABIERTA -------------------------------
double tiempoNetoPosic(string simb, mi_FECHA_HORA modo= _SEG)
{              //devuelve el tiempo en segundos TIEMPO EFECTIVO DE MERCADO
   datetime arTmpBarra[],
            horaIni= (datetime)PositionGetInteger(POSITION_TIME);,
            horaFin= TimeCurrent();
   double contTmp= horaIni>0? CopyTime(simb, PERIOD_M1, horaIni, horaFin, arTmpBarra): -1; //el inicio de las barras queda dentro del intervalo definido
   if(contTmp>0)
   {
      contTmp= contTmp*60;                   //+(horaFin-arTmpBarra[(int)contTmp-1])+(horaIni-arTmpBarra[0]);
      switch(modo)
      {
         case _DIA  : contTmp= contTmp/(60*60*24);   break; // calcula número de días
         case _HORA : contTmp= contTmp/(60*60);      break; // calcula número de horas
         case _MIN  : contTmp= contTmp/60;           break; // calcula número de minutos
         case _SEG  : contTmp= contTmp;                     // calcula segundos
      }
   }
   return(contTmp);          //devuelve -1 si ha habido error
}
Osama Shaban
1464
Osama Shaban 2015.04.03 23:13  
It is enough to code a function to compare current time with order open time ... Once difference is >= 0, then close the order.
To add comments, please log in or register