Sleep function problem - page 2

 
ALI AMRIOUI #:
Coz he is using seconds and i told u my friend i wana working with Sleep function means miliseconds
That does not invalidate the explanation
 
Samuel Manoel De Souza #:
If you replace the return by Sleep it shall work.
Yeah,, its Good idea i will try it
Thanks friend
 
if(TimeCurrent() < LastClosed("CloseTime")+3600 )
 {
return;

}
Samuel Manoel De Souza #
:

If you replace the return by Sleep it shall work.
  • like that its work .. but with seconds no milliseconds
  •  but when i try replace  return  by Sleep function it does not work 
  • how i can replace sleep() function  in return
 
Samuel Manoel De Souza #:
That does not invalidate the explanation
int x =3600000;

if(TimeCurrent() < LastClosed("CloseTime")+x )
 {
Sleep(x);

}

like that does not work 

 
Any one have a idea about Sleep() function?? 
 
ALI AMRIOUI #:

like that does not work 

int x =3600000;

if(TimeCurrent() < LastClosed("CloseTime")+ x/1000)
 {
Sleep(x);

}
 
Samuel Manoel De Souza #:

That sleeps for an hour, and if the time has not passed, it sleeps for another hour. It does that even if the last closed order with 59 minutes ago. Not what OP wanted.

 
William Roeder #:

That sleeps for an hour, and if the time has not passed, it sleeps for another hour. It does that even if the last closed order with 59 minutes ago. Not what OP wanted.

actually he can place anything lower than 3600 seconds in place of x/1000. like 5 or 10 seconds. just to check if an orders has been closed. Or check only the orders that hass been opened by the EA, if the OrderCloseTime was 0 and changed to something different, than the order has been closed. Just need think a little bit.

 
Samuel Manoel De Souza #:

actually he can place anything lower than 3600 seconds in place of x/1000. like 5 or 10 seconds. just to check if an orders has been closed. Or check only the orders that hass been opened by the EA, if the OrderCloseTime was 0 and changed to something different, than the order has been closed. Just need think a little bit.

thanks friend for u hlep but its does not work .. u can check it with u self and  .. this is EA complet 

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+


bool Trade =True;
extern double lot = 0.01 ;
extern double TP = 0 ;
extern double SL = 0 ;
extern int MagicNumber1 = 1917 ;
input string EaName = "ATLAS" ;
double MyPoint, Buyt, Buys, Sellt, Sells, cnt  ;
int Ticket1,Decimal ;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

   if(Digits ==4 || Digits <=2)
      MyPoint=Point ;
   if(Digits ==3 || Digits ==5)
      MyPoint=Point*10 ;

   if(MarketInfo(Symbol(),MODE_MINLOT)<0.1)
      Decimal =2;
   else
      Decimal=1;


   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {


  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()

  {

   if(TP == 0)
      Buyt = 0;
   else
      Buyt= Ask+TP*MyPoint;
   if(SL == 0)
      Buys = 0;
   else
      Buys= Ask-SL*MyPoint;

   if(TP == 0)
      Sellt = 0;
   else
      Sellt= Bid-TP*MyPoint;
   if(SL == 0)
      Sells = 0;
   else
      Sells= Bid+SL*MyPoint;




//SLEEP FUNCTION

int x =3600000;

if(TimeCurrent() < LastClosed("CloseTime")+x/1000 )
 {
Sleep(x);

}






   if(Trade)
     {
      //SELLSTOP3
      if(TS()==0)

        {

         Ticket1= OrderSend(Symbol(),OP_SELL,lot,Bid,1,   Sells,  Sellt,EaName,MagicNumber1,0,clrRed);
        }
     }

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int TS()
  {

   int s=0,i;
   for(i =0 ; i < OrdersTotal() ; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES))
         if(Symbol()== OrderSymbol()&& OrderMagicNumber() == MagicNumber1&& OrderType() == OP_SELL)
           {
            s++ ;

           }
     }
   return (s) ;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+


// last closeinfo

double LastClosed(string S,int type =-1)
  {

   for(int f = OrdersHistoryTotal() -1 ; f>=0; f--)
     {

      if(OrderSelect(f,SELECT_BY_POS,MODE_HISTORY))
         if(OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber1 && (OrderType()== type || type ==-1))
           {

            if(S=="Lots")
               return(OrderLots());
            else
               if(S=="OpenPrice")
                  return(OrderOpenPrice());
               else
                  if(S=="ClosePrice")
                     return(OrderClosePrice());
                  else
                     if(S=="TP")
                        return(OrderTakeProfit());
                     else
                        if(S=="SL")
                           return(OrderStopLoss());
                        else
                           if(S=="Type")
                              return(OrderType());
                           else
                              if(S=="Profit")
                                 return(OrderProfit());
                              else
                                 if(S=="OpenTime")
                                    return(OrderOpenTime());
                                 else
                                    if(S=="CloseTime")
                                       return(OrderCloseTime());
                                    else
                                       if(S=="Com")
                                          return(OrderCommission());
                                       else
                                          if(S=="SWAP")
                                             return(OrderSwap());
                                          else
                                             if(S=="Magic")
                                                return(OrderMagicNumber());



           }
     }
   return(0);


  }








 
Maybe we should working also with GetTickCount() function
Reason: