Help with MT4 EA for hours.

 
I do not speak good English, so this is a translation of google, sorry.
This is my first EA, it compares the price to one hour with respect to past and it sell to future hour. I know it's not perfect, but understand that I am not a programmer. My problem is that I need to sell the position at the time indicated on another day, not today, tomorrow or after tomorrow ie. So did the comparison, yesterday or the day before.
I hope I explained well and thanks for the help.
Best regards.
extern string Hora_de_comparación="07:01";
extern string Hora_de_apertura="08:01";
extern string Hora_de_cierre="09:01";
extern double Volumen=0.01;
extern int Stop_loss=50;
extern int Take_profit=50;

void abrircompra()
 {
  OrderSend(Symbol(),OP_BUY,Volumen,Ask,5,Ask-Stop_loss,Ask+Take_profit);
 }

void abrirventa()
 {
  OrderSend(Symbol(),OP_SELL,Volumen,Bid,5,Bid+Stop_loss,Bid-Take_profit);
 }
  
void cerrar()
 {
  int error=0;
  int total=OrdersTotal();
  for(int pos = total-1; pos >= 0; pos--)
   {
    OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
    if(OrderType() != 0 && OrderType() != 1) OrderDelete(OrderTicket(),Yellow);
    else if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Yellow))
     {
      error=GetLastError(); Print("Error de cierre = ",error);
      return(error); 
     }
   }
  return(error);
 }
 
int start()
 {
  datetime hora_comparacion=StrToTime(Hora_de_comparación);
  datetime hora_apertura=StrToTime(Hora_de_apertura);
  datetime hora_cierre=StrToTime(Hora_de_cierre);
  int hora=TimeHour(TimeCurrent());
  int minuto=TimeMinute(TimeCurrent());

  for (int a=0;Hora_de_comparación!=TimeToStr(Time[a],TIME_MINUTES);a++) //Comparación
   {
    double precio_comparacion=Open[a+1];
   }
  if(hora==TimeHour(hora_apertura) && minuto==TimeMinute(hora_apertura)) 
   {
    if (Open[0] <= precio_comparacion)
     {
      abrircompra();
     }
    else
     {
      abrirventa();
     }   
   } 
  if(hora==TimeHour(hora_cierre) && minuto==TimeMinute(hora_cierre))
   {
    cerrar();
   } 
  return(0);
 }
 

Sorry, I have no idea what you are asking.

But this needs some work

 OrderSend(Symbol(),OP_BUY,Volumen,Ask,5,Ask-Stop_loss,Ask+Take_profit);

If Ask is 1.30000

you are setting your stop at 1.30000 minus 50, so your stop will be -48.7 and your TP will be 51.30000

 
That's not important, I work with indexes. Sorry I did not explain myself better in English.
My EA compares the price at 7:01 with the 8:01, then buy or sell. Then close the position at 9:01. But I want to close the position at 9:01 tomorrow or after tomorrow, not today, and I do not know how. Any suggestions?
 
junji: But I want to close the position at 9:01 tomorrow or after tomorrow, not today,
Then make sure the position has been opened for at least 24 hours
#define HR2400 86400       // 24 * 3600
int      TimeOfDay(datetime when){  return( when % HR2400          );         }
datetime DateOfDay(datetime when){  return( when - TimeOfDay(when) );         }
//datetime Today(){                   return(DateOfDay( TimeCurrent() ));       }
//datetime Tomorrow(){                return(Today() + HR2400);                 }
//datetime Yesterday(){               return( iTime(NULL, PERIOD_D1, 1) );      }
///////
for(...) if(OrderSelect(...) && ...){ // See https://forum.mql4.com/56292#806175
   datetime now = TimeCurrent(),
            then = OrderOpenTime();
   if(now - then > HR2400) ...
 
I need time to study it and try it. Thank you very much.
 
I have already finished my EA, but I have a problem. When it comes time to open, it opens up many operations. How I can fix it?
Reason: