Code to prematurely end execution of script?

 

Hi, I am making an expert advisor that runs on every tick. I am trying to find a way to end the execution of the script prematurely when a condition is met early on in the script, and then the script won't execute again until the next tick. I know I could just put the entire code after the condition into a an if statement, but am wondering if there's a more elegant method? 

void OnTick()
{


double ordersopen[] ;
string symbolsopen[] ;
ArrayResize ( symbolsopen , 1 ) ;
int symbols = 0 ;

for ( int i = OrdersTotal() - 1 ; i + 1 > 0 ; i-- )
   {
   OrderSelect( i , SELECT_BY_POS ) ;
   if ( OrderSymbol() == Symbol() )
      {
      ArrayResize( ordersopen , ArraySize( ordersopen ) + 1 ) ;
      ArrayFill( ordersopen , ArraySize( ordersopen ) - 1 , 1 , OrderTicket() ) ;
      }
   for ( int j = 0 ; j < ArraySize( symbolsopen ) ; j++ )
      {
      if ( OrderSymbol() == symbolsopen[ j ] )
         {
         break ;
         }
      if ( j == ArraySize( symbolsopen ) - 1 )
         {       
         ArrayResize( symbolsopen , ArraySize( symbolsopen ) + 1 ) ;        
         symbolsopen[ ArraySize( symbolsopen ) - 1 ] = OrderSymbol() ;
         symbols += 1 ;
         }
      }     
   }
   

if ( ( symbols == 3 ) && ( ArraySize( ordersopen ) == 0 ) )
   {
   //end execution
   }


//rest of code

}

As you can see from my code, the condition that should end the execution of the script is if the number of symbols with open positions is equal to 3, and that the current symbol doesn't have any open positions. I'm using MQL4 by the way.

 
if ( ( symbols == 3 ) && ( ArraySize( ordersopen ) == 0 ) )
   {
    return; //end execution
   }

Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.