How can i automaticly repeat the task of my EA when it's done can you help please thanks.

 

Below is my source code when the task is done i want it to be repeated automaticly i cant find the way to do it any help will be apreciated.

void OnTick()
  {
   int PositionIndex;
   int TotalNumberOfOrders;
   slippage=10;
   volume=0.01;
   Count++;
 
       
   if(Count==1  )
     {
                ticket1=OrderSend(Symbol(),OP_BUYSTOP,1,Ask+4*Point,5,Ask-2*(StopLoss*Point),Ask+2.5*(TakeProfit*Point),NULL,243,0,clrNONE);
                if(ticket1<0)
                Print("Error opening BUYSTOP order : ",GetLastError());
                ticket2=OrderSend(Symbol(),OP_SELLSTOP,1,Bid-3*Point,5,Bid+2*(StopLoss*Point),Bid-2.5*(TakeProfit*Point),NULL,144,0,clrNONE);
                if(ticket2<0)
                Print("Error opening SELLSTOP order : ",GetLastError());
     }
       
  while(true&&Count==1&&ticket1>1&&ticket2>1){
    TotalNumberOfOrders=OrdersTotal();
 
   for(PositionIndex=TotalNumberOfOrders-1; PositionIndex>=0; PositionIndex --)
     {
      if(!OrderSelect(PositionIndex,SELECT_BY_POS,MODE_TRADES ))
        {
         continue;
        }
      if((OrderMagicNumber()==ticket1 || OrderMagicNumber()==ticket2) && OrderSymbol()==Symbol() && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP))

        {
         continue;
        }
      if(OrderType()==OP_SELL)
                              {
       result=OrderDelete(ticket1,clrNONE);//EURUSD-->BUY
       result=OrderDelete(ticket2,clrNONE);//EURUSD--->SELL
                        }
      else if(OrderType()==OP_BUY)
                        {
       result=OrderDelete(ticket1,clrNONE);//EURUSD-->BUY
       result=OrderDelete(ticket2,clrNONE);//EURUSD--->SELL
                         }
          }
    }
    
    
   for(PositionIndex=TotalNumberOfOrders-1; PositionIndex>=0; PositionIndex --)
     {
         if(!OrderSelect(PositionIndex,SELECT_BY_POS,MODE_TRADES) )
         if((OrderMagicNumber()==ticket1 || OrderMagicNumber()==ticket2) && OrderSymbol()==Symbol() && (ticket1==OP_BUY || ticket2==OP_SELL))
         if(OrderType()==OP_SELL   )//SELL ORDER On Positif TRADE
         if(!OrderClose(ticket2,0.01,5 ,clrNONE) )
         Print("Price on positif side  -----> ", Bid-Price*Point );      
         if(OrderType()==OP_SELL  )//SELL ORDER On Negatif TRADE
         if(!OrderClose(ticket2,0.01,5,clrNONE))
         
         if(OrderType()==OP_BUY   )//BUY ORDER On Positif TRADE
         if(!OrderClose(ticket1,0.01,5,clrNONE))
         Print("Price on positif side -----> " ,Ask+Price*Point  );
         if(OrderType()==OP_BUY    )//BUY ORDER On Negatif TRADE
         if(!OrderClose(ticket1,0.01,5,clrNONE))
         Print("Order Close failed, order number: ",ticket1," Error: ",GetLastError());
    }
       
           
  }
 
Stone Fletcher: Below is my source code when the task is done i want it to be repeated automaticly i cant find the way to do it any help will be apreciated.

Perhaps you should read the manual. OnTick is called for each new tick, so it will "be repeated automatically." There isn't a way to not "do it."

 
whroeder1:

Perhaps you should read the manual. OnTick is called for each new tick, so it will "be repeated automatically." There isn't a way to not "do it."


OnTick() return this error when i use it ouside the void type : 'OnTick' - expression of 'void' type is illegal in the manual it is said that  It must be declared as the void type, with no parameters:

so how can i use it ??? 


 
void OnTick()
  {

You already "declared as the void type, with no parameters."  You do not call it, the terminal calls it.

 
whroeder1:

You already "declared as the void type, with no parameters."  You do not call it, the terminal calls it.


Ok i know the terminal already called it but  it does not repeat the task when the task is done when i start the program it goes one time then when it is finish it does not repeat even with the void OnClick() so i do not understand what you try to tell me !! i tried while loop around the source code it does not work can you be more specific thanks.

 

There is no such function OnClick().

Stop adding code! The problem is not the code.

OnTick() is call when there is a new tick. That is what I tried to tell you. Nothing more. 

Are you connected to a broker? Is there a smiley face?

 
whroeder1:

There is no such function OnClick().

Stop adding code! The problem is not the code.

OnTick() is call when there is a new tick. That is what I tried to tell you. Nothing more. 

Are you connected to a broker? Is there a smiley face?


I'm actually connected to broker account on the top rigth corner of my chart the name of my EA (TEST88) is there i do not see the Smiley face.  Did i forgot to do something to see the smiley face??

here is a picture: 

my chart with the EA on top rigth corner

 

Because you are running Linux and do not have the windows font with the smiley face installed.

The EA is loaded on your chart.

A dirty way to restart an EA is by calling OnInit() function, But it is not in your code...

 

Your problem is your "Count" variable.  

The terminal is connected and receives ticks, and they trigger OnTick (), but every time this function is called, you add 1 to the value of the Count variable, therefore, that variable will only have a value = 1 the first time OnTick() is called.

The value of this variable will increase (the next time will be 2, then 3, 4, 5, 6 .... etc), and therefore the rest of functions are NOT executed since one of the conditions for them to be executed is which Count == 1.


Why if Count == 1 ???


void OnTick()
  {
   int PositionIndex;
   int TotalNumberOfOrders;
   slippage=10;
   volume=0.01;
   Count++;
 
       
   if(Count==1  )
     {
                ............................
     }
       
  while(true&&Count==1&&ticket1>1&&ticket2>1){
    TotalNumberOfOrders=OrdersTotal();
 
                 ...........................
    }
 
Jose Francisco Casado Fernandez:

Your problem is your "Count" variable.  

The terminal is connected and receives ticks, and they trigger OnTick (), but every time this function is called, you add 1 to the value of the Count variable, therefore, that variable will only have a value = 1 the first time OnTick() is called.

The value of this variable will increase (the next time will be 2, then 3, 4, 5, 6 .... etc), and therefore the rest of functions are NOT executed since one of the conditions for them to be executed is which Count == 1.


Why if Count == 1 ???



I removed the Count variable after i tried it without doing Count==1 but just Count and still does not repeat the task it does it once a nothing after that  i dont understand what is the problem if i got the function OnClick() why it does not repeat the task ????

 
Marco vd Heijden:

Because you are running Linux and do not have the windows font with the smiley face installed.

The EA is loaded on your chart.

A dirty way to restart an EA is by calling OnInit() function, But it is not in your code...


it is not working !!

Reason: