trade at time

 

hi guys  i try to  close  a trade at  time ,

i  open the  trade at time  and  it works  but  when i try to close  not close 

i create  a script like this

extern string StartTime ="11:00:00";
extern string EndTime ="12:00:00";

if(TimeToString(TimeLocal(),TIME_SECONDS)> EndTime)
     {
      Print("SONO QUI 1  "+TimeToString(TimeLocal(),TIME_SECONDS)+" ---- "+ EndTime);
      if(OrderMagicNumber() == MagicNumb)
        {
         for(int i= OrdersTotal()-1; i>=0; i--)
           {
            if(OrderType() == OP_BUY)
              {
               //---- close the position
               OrderClose(OrderTicket(), OrderLots(), Bid, 5, Green);
              }

            //---- if the SELL position has been opened,
            if(OrderType() == OP_SELL)
              {
               //---- close the position
               OrderClose(OrderTicket(), OrderLots(), Ask, 5, Red);
              }
           }
        }
     }

any one  can help me ?  thanks

 
faustf:

hi guys  i try to  close  a trade at  time ,

i  open the  trade at time  and  it works  but  when i try to close  not close 

i create  a script like this

any one  can help me ?  thanks

i think you should have to compare date/time, not string.

 
but i convert  o_O   why you tell me not compare string ?, and  why for open work ???
TimeToString(TimeLocal(),TIME_SECONDS)
 
faustf: but i convert  o_O   why you tell me not compare string ?, and  why for open work ???
extern string EndTime ="12:00:00";

if(TimeToString(TimeLocal(),TIME_SECONDS)> EndTime)

Because “2020.MM.DD HH:MM:SS” is always greater than “12:00:01” since “20” > “12”

if(TimeLocal() > StringToTime(EndTime)
 

Because “2020.MM.DD HH:MM:SS” is always greater than “12:00:01” since “20” > “12”

if(TimeLocal() > StringToTime(EndTime)


but if i use    this 

TimeToString(TimeLocal(),TIME_SECONDS)

the Print return me only  a time  21:00:15 (fore example )

i want use only  the  time not interest a date