EA action without tick

 

Hello, I have a question, is there a way to code EA to make more than 1 cycle (e.g OrderSend) after getting a tick form market.

Sometimes time between tick's is long and I want to open 3 buy orders. Today with my coding skills I need to wait for 3 market ticks to occure to get 3 buy orders open.

Is there a way when first tick is generated EA will not stop until EA code has "checked/made all changes" what it was supposed to do and wait for next tick.


Here is a sample of code that takes at least 3 maket ticks to "finish". Can all this be done (open 3 buy orders) starded by 1 tick? If MQL4 code cannot be programmed like this, can you suggest some other solution to look into?

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

int   Magic          =  100;       //Magic number for Buy ID       

void OnTick()
  {
      int   BuyTotal =  0;         //Buy Orders
      
      for(int v=OrdersTotal()-1;v>=0;v--)
      {
         if(OrderSelect(v,SELECT_BY_POS,MODE_TRADES))
         {  
            if(OrderSymbol()==Symbol()
            && OrderType()==OP_BUY 
            && OrderMagicNumber()==Magic)
            {
               BuyTotal++;
            }
         }
      }
      //Open Buy Orders
      if(BuyTotal<3)
      {

      int ticket=OrderSend(Symbol(),OP_BUY,1.00,Ask,3,0,0,"I.Am.A.Buy.Order",Magic,0,clrNONE);
         if(ticket<0)
         {
            Print("OrderSend failed with error #",GetLastError());
         }
         else
         {
            Print("OrderSend placed successfully");
         }
      }
      //Comment On Chart
      Comment("BuyTotal | ",BuyTotal);
  }  
 
Rahle: Can all this be done (open 3 buy orders) starded by 1 tick?
Of course, you just have to refresh the predefined variables between server calls.
//    if(BuyTotal<3)
      while(BuyTotal<3)
      {                                                                                       
      RefreshRates();
      int ticket=OrderSend(Symbol(),OP_BUY,1.00,Ask,3,0,0,"I.Am.A.Buy.Order",Magic,0,clrNONE);
         if(ticket<0)                                                                         
          {                                                                                   
            Print("OrderSend failed with error #",GetLastError());                            
         }                                                                                    
         else                                                                                 
         {                                                                                    
            Print("OrderSend placed successfully");                                           
            BuyTotal++;
         }                                                                                    
      }                                                                                       

 
WHRoeder:
Rahle: Can all this be done (open 3 buy orders) starded by 1 tick?
Of course, you just have to refresh the predefined variables between server calls.

Thank you WHRoeder! It is exactly as I needed.