Slawa you now have me extremely worried. Question please?

 
Hi Slawa,

Got your message before and I dont see the problem with using sleep function between trading operations as a delay. This is the expert im using below, and it works fine on a demo account. Im now worried about what you said about "game for all money" what doies this phrase mean?

Is there a problem with the code im using below in the way im using the sleep() function?

//+------------------------------------------------------------------+
//|                                                                  |
//|                                       Expert Advisor Sample.MQL4 |
//|                                 Copyright © 2006, Fraser Capital |
//|                                                                  |
//+------------------------------------------------------------------+



extern double LotsA = 1.00; // trading 1.00 lot with FXDD broker
extern double LotsB = 2.00; // trading 2.00 lots with FXDD broker
extern double LotsC = 3.00; // trading 3.00 lots with FXDD broker



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int start()
 {
 
 
  while(Bars>10) // use of while function to create an endless loop (within the start function)
  { // // // // 


   RefreshRates();
   
   
   // No orders are currently open - i.e. OrdersTotal=0
   if(OrdersTotal()==0) 
   {

      // Entry (Open Order) Condition:      
      if(Bid>High[1])
      {
        
        RefreshRates();
        OrderSend(Symbol(),OP_BUY,LotsA,Ask,0,0,0,"",13,0,Aqua); // name this Order LotsA
        Sleep(8000);    
              
       }
   }        


////////////////////////////////////////////////////////////////////////////////////////////


   // 1 order (LotsA)is currently open
   OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
   if(OrdersTotal()==1 && OrderLots()==LotsA && OrderType()==OP_BUY) 
   {

      // Entry (Open Order) Condition:      
      if(Bid>High[1])
      {
        
        RefreshRates();
        OrderSend(Symbol(),OP_BUY,LotsB,Ask,0,0,0,"",13,0,Aqua); // 
        Sleep(8000);  // Wait 8 seconds    
              
       }
   }        


///////////////////////////////////////////////////////////////////////////////////////////


   // 2 orders (LotsA and LotsB)are currently open
   OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
   if(OrdersTotal()==2 && OrderLots()==LotsA && OrderType()==OP_BUY) 
   {
     OrderSelect(1, SELECT_BY_POS, MODE_TRADES);
     if(OrdersTotal()==2 && OrderLots()==LotsB && OrderType()==OP_BUY) 
     {   
       // Entry (Open Order) Condition:      
       if(Bid>High[1])
       {
        
        RefreshRates();
        OrderSend(Symbol(),OP_BUY,LotsC,Ask,0,0,0,"",13,0,Aqua); // 
        Sleep(8000);  // Wait 8 seconds    
              
       }
     }        
   }


///////////////////////////////////////////////////////////////////////////////////////////
   
   
   // SELL conditions:
   if(OrdersTotal()==0) 
   {

      // Entry (Open Order) Condition:      
      if(Bid<Low[1])
      {
            
        RefreshRates();
        OrderSend(Symbol(),OP_SELL,LotsA,Bid,0,0,0,"",13,0,Yellow); // 
        //Sleep(8000);  // Wait 8 seconds    
              
       }
   }        


////////////////////////////////////////////////////////////////////////////////////////////


   // 1 order (LotsA)is currently open
   OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
   if(OrdersTotal()==1 && OrderLots()==LotsA && OrderType()==OP_SELL) 
   {

      // Entry (Open Order) Condition:      
      if(Bid<Low[1])
      {
        RefreshRates();
        OrderSend(Symbol(),OP_SELL,LotsB,Bid,0,0,0,"",13,0,Yellow); // name this Order LotsB
        Sleep(8000);  // Wait 8 seconds    
              
       }
   }        


///////////////////////////////////////////////////////////////////////////////////////////


   // 2 orders (LotsA and LotsB)are currently open
   OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
   if(OrdersTotal()==2 && OrderLots()==LotsA && OrderType()==OP_SELL) 
   {
     OrderSelect(1, SELECT_BY_POS, MODE_TRADES);
     if(OrdersTotal()==2 && OrderLots()==LotsB && OrderType()==OP_SELL) 
     {   
       // Entry (Open Order) Condition:      
       if(Bid<Low[1])
       {
       
        RefreshRates();
        OrderSend(Symbol(),OP_SELL,LotsC,Bid,0,0,0,"",13,0,Yellow); 
        Sleep(8000);  // Wait 8 seconds    
              
       }
     }        
   }



///////////////////////////////////////////////////////////////////////////////////////////



   // Exit (Close Order LotsA) Condition:
   
   // There is 1 open order i.e. OrdersTotal=1
   if( OrdersTotal()==1 ) 
   {
      OrderSelect(0, SELECT_BY_POS, MODE_TRADES);

         if(OrderType()==OP_BUY && OrderLots()==LotsA)   // long position was opened
        {
            if(Bid<Low[1])
            {
               RefreshRates();
               OrderClose(OrderTicket(),OrderLots(),Bid,0,Violet); // close position
               Sleep(8000);  // Wait 8 seconds    
            }
        }
   }
     
     
     
////////////////////////////////////////////////////////////////////////////////////////////     
   
   
   
   // Exit (Close Order LotsB) Condition:
   
   // There is 2 open orders i.e. OrdersTotal=2
   if( OrdersTotal() == 2 ) 
   {
      OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_BUY && OrderLots()==LotsA)   
      {  
        OrderSelect(1, SELECT_BY_POS, MODE_TRADES);
        if(OrderType()==OP_BUY && OrderLots()==LotsB)  
        {
        
            if(Bid<Low[1])
            {
              RefreshRates();
              OrderClose(OrderTicket(),OrderLots(),Bid,0,Violet); // close position
              Sleep(8000);  // Wait 8 seconds    
            }
         }
       }
   } 
  
  
////////////////////////////////////////////////////////////////////////////////////////////  



   // Exit (Close Order LotsB) Condition:
   
   // There is 3 open orders i.e. OrdersTotal=3
   if( OrdersTotal() == 3 ) 
   {
      OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_BUY && OrderLots()==LotsA)   
      {  
        OrderSelect(1, SELECT_BY_POS, MODE_TRADES);
        if(OrderType()==OP_BUY && OrderLots()==LotsB)  
        {
          OrderSelect(2, SELECT_BY_POS, MODE_TRADES);
          if(OrderType()==OP_BUY && OrderLots()==LotsC)  
          {

            if(Bid<Low[1])
            {
               RefreshRates();
               OrderClose(OrderTicket(),OrderLots(),Bid,0,Violet); // close position
               Sleep(8000);  // Wait 8 seconds    
            }
          }
        }
      } 
   }
  
  
////////////////////////////////////////////////////////////////////////////////////////////  



   // Exit (Close Order LotsA) Condition:
   
   // There is 1 open order i.e. OrdersTotal=1
   if( OrdersTotal()==1 ) 
   {
      OrderSelect(0, SELECT_BY_POS, MODE_TRADES);

         if(OrderType()==OP_SELL && OrderLots()==LotsA)   // long position was opened
        {
            if(Bid>High[1])
            {
               RefreshRates();
               OrderClose(OrderTicket(),OrderLots(),Ask,0,Violet); // close position
               Sleep(8000);  // Wait 8 seconds    
            }
        }
   }
     
     
     
////////////////////////////////////////////////////////////////////////////////////////////     
   
   
   
   // Exit (Close Order LotsB) Condition:
   
   // There is 2 open orders i.e. OrdersTotal=2
   if( OrdersTotal() == 2 ) 
   {
      OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_SELL && OrderLots()==LotsA)   
      {  
        OrderSelect(1, SELECT_BY_POS, MODE_TRADES);
        if(OrderType()==OP_SELL && OrderLots()==LotsB)  
        {
        
            if(Bid>High[1])
            {
               RefreshRates();
               OrderClose(OrderTicket(),OrderLots(),Ask,0,Violet); // close position
               Sleep(8000);  // Wait 8 seconds    
            }
         }
      }
   } 
  
  
////////////////////////////////////////////////////////////////////////////////////////////  



   // Exit (Close Order LotsB) Condition:
   
   // There is 3 open orders i.e. OrdersTotal=3
   if( OrdersTotal() == 3 ) 
   {
      OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_SELL && OrderLots()==LotsA)   
      {  
        OrderSelect(1, SELECT_BY_POS, MODE_TRADES);
        if(OrderType()==OP_SELL && OrderLots()==LotsB)  
        {
          OrderSelect(2, SELECT_BY_POS, MODE_TRADES);
          if(OrderType()==OP_SELL && OrderLots()==LotsC)  
          {

            if(Bid>High[1])
            {
               RefreshRates();
               OrderClose(OrderTicket(),OrderLots(),Ask,0,Violet); // close position
               Sleep(8000);  // Wait 8 seconds    
            }
          }
        }
      } 
   }
  
  
  }// while - endless loop within start() function
 
 } // start

// the end



Thanks Slawa. I really am grateful for your kind help.

Kind regards

Rod

 
There is your sample in your previous question
{
   RefreshRates();
   OrderSend(Symbol(),OP_BUY,Lots2,Ask,Slippage,Ask-StopLoss2*Point,OrderTakeProfit(),"",0,0,Blue); 
   Sleep(6000); // Wait 6 seconds
}


If it is endless loop, then it is "game for all money"

Once more. There is no problem with delay between trade operations. No official permissions about this. But your broker can lock you if this broker considers you to make trade operations too frequently. The broker can determine the annoying frequency for each particular case independently.

In my opinion, you should keep at 30-second delay, though I cannot support this my opinion in any way exactly. It is like intuition. In some extreme cases, for example, if you want to close all positions urgently, you can use OrderClose function without any delays at your responsibility.

See also "MQL4: Execution errors"

Reason: