if expression are not allowed on global scope

 
hi guys i have tried for hours and still couldn't find the problem on this code im new to coding so i don't know exactly what to look for i saw another page dedicated to this that said to check if the brackets were all good, i cheked and they seem good how can i fix it?
int OnInit()
{
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
 {
   double mainStoch_1 = iStochastic( Symbol(), PERIOD_CURRENT, 5, 3, 3, MODE_SMA, STO_LOWHIGH, MODE_MAIN, 1 );
   
   double mainStoch_2 = iStochastic( Symbol(), PERIOD_CURRENT, 5, 3, 3, MODE_SMA, STO_LOWHIGH, MODE_MAIN, 2 );
   
   double signalStoch_1 = iStochastic( Symbol(), PERIOD_CURRENT, 5, 3, 3, MODE_SMA, STO_LOWHIGH, MODE_SIGNAL, 1 );
   
   double signalStoch_2 = iStochastic( Symbol(), PERIOD_CURRENT, 5, 3, 3, MODE_SMA, STO_LOWHIGH, MODE_SIGNAL, 2 );
   
   bool ariete = mainStoch_1 > signalStoch_1 &&
                       mainStoch_2 <= signalStoch_2 && mainStoch_1 < 20;
                       
   bool trezzo = mainStoch_1 < signalStoch_1 &&
                       mainStoch_2 >= signalStoch_2 && mainStoch_1 > 80;
                       }
   
   
 if (ariete && !presenteOrdineMercatoBarra() )
   {
   inserisciOrdineBuyEChiudiSell ( 0.1, "Buy" )
   }
   
   
 if (trezzo && !presenteOrdineMercatoBarra() )
   {
   inserisciOrdineSellEChiudiBuy ( 0.1 "Sell" )
   }
   
  
 
 

 
 input int magic = 1;                //Magic Number

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool presenteOrdineMercato()
{
   for( int i = OrdersTotal() -1; i >= 0; i-- )
   {
      if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == magic )
      {
         return true;
      }
   }
   
   return false;
}

bool presenteOrdineMercatoBarra()
{
   for( int i = OrdersTotal() -1; i >= 0; i-- )
   {
      if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == magic &&
          OrderOpenTime() >= Time[0] )
      {
         return true;
      }
   }
   
   return false;
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void inserisciOrdineBuy( double _lotti, string _commento )
{
   int ticket = OrderSend( Symbol(), OP_BUY, _lotti, Ask, 20, 0.0, 0.0, _commento, magic, 0, clrBlue );
         
   if( ticket == -1 )
   {
      Alert( IntegerToString( magic ) + " "+ 
             " errore inserimento ordine buy : " + IntegerToString( GetLastError() ) );
   } 
   else
   {
      Alert( IntegerToString( magic ) + " "+ "inserito ordine buy " );
   }
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void inserisciOrdineSell(double _lotti, string _commento )
{   
   int ticket = OrderSend( Symbol(), OP_SELL, _lotti, Bid, 20, 0.0, 0.0, _commento, magic, 0, clrRed );
         
   if( ticket == -1 )
   {
      Alert( IntegerToString( magic ) + " "+ 
             " errore inserimento ordine sell : " + IntegerToString( GetLastError() ) );
   } 
   else
   {
      Alert( IntegerToString( magic ) + " "+ "inserito ordine sell " );
   }
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void inserisciOrdineBuyEChiudiSell(double _lotti, string _commento )
{
   chiudiOrdineSell();
   
   int ticket = OrderSend( Symbol(), OP_BUY, _lotti, Ask, 20, 0.0, 0.0, _commento, magic, 0, clrBlue );
         
   if( ticket == -1 )
   {
      Alert( IntegerToString( magic ) + " "+ 
             " errore inserimento ordine buy : " + IntegerToString( GetLastError() ) );
   } 
   else
   {
      Alert( IntegerToString( magic ) + " "+ "inserito ordine buy " );
   }
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void inserisciOrdineSellEChiudiBuy(double _lotti, string _commento )
{
   chiudiOrdineBuy();
   
   int ticket = OrderSend( Symbol(), OP_SELL, _lotti, Bid, 20, 0.0, 0.0, _commento, magic, 0, clrRed );
         
   if( ticket == -1 )
   {
      Alert( IntegerToString( magic ) + " "+ 
             " errore inserimento ordine sell : " + IntegerToString( GetLastError() ) );
   } 
   else
   {
      Alert( IntegerToString( magic ) + " "+ "inserito ordine sell " );
   }
}

//+------------------------------------------------------------------+
//|                          Chiudi Magic                            |
//+------------------------------------------------------------------+
void chiudiOrdineBuy()
{
   string _causale = "";
     
   for( int i = OrdersTotal(); i >= 0; i-- )
   {
      if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == magic && OrderType() == OP_BUY )
      {
         for( int k = 0; k < 10; k++ )
         {
            RefreshRates();
            if( !OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 20, clrRed ))
            {
               Alert( IntegerToString( magic ) + " "+ 
                     " errore chiurura ordine buy : " + IntegerToString( GetLastError() ) );
            }
            else 
            {
               Alert( IntegerToString( magic ) + " "+ "inserito ordine buy " );
               break;
            }
         }
      }
   }
}

void chiudiOrdineSell()
{
   string _causale = "";
     
   for( int i = OrdersTotal(); i >= 0; i-- )
   {
      if( OrderSelect( i, SELECT_BY_POS ) && OrderMagicNumber() == magic && OrderType() == OP_SELL )
      {
         for( int k = 0; k < 10; k++ )
         {
            RefreshRates();
            if( !OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 20, clrRed ))
            {
               Alert( IntegerToString( magic ) + " "+ 
                     " errore chiurura ordine sell : " + IntegerToString( GetLastError() ) );
            }
            else 
            {
               Alert( IntegerToString( magic ) + " "+ "inserito ordine sell " );
               break;
            }
         }
      }
   }
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void inserisciOrdineBuy( string _strumento, double _lotti, string _commento )
{
   int ticket = OrderSend( _strumento, OP_BUY, _lotti, 
                           SymbolInfoDouble( _strumento, SYMBOL_ASK), 
                           20, 0.0, 0.0, _commento, magic, 0, clrBlue );
         
   if( ticket == -1 )
   {
      Alert( _strumento + " " + 
             IntegerToString( magic ) + " "+ 
             " errore inserimento ordine buy : " + IntegerToString( GetLastError() ) );
   } 
   else
   {
      Alert( _strumento + " " + 
             IntegerToString( magic ) + " "+ "inserito ordine buy " );
   }
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void inserisciOrdineSell( string _strumento, double _lotti, string _commento )
{
   int ticket = OrderSend( _strumento, OP_SELL, _lotti, 
                           SymbolInfoDouble( _strumento, SYMBOL_BID ), 
                           20, 0.0, 0.0, _commento, magic, 0, clrRed );
         
   if( ticket == -1 )
   {
      Alert( _strumento + " " + 
             IntegerToString( magic ) + " "+ 
             " errore inserimento ordine sell : " + IntegerToString( GetLastError() ) );
   } 
   else
   {
      Alert( _strumento + " " + 
             IntegerToString( magic ) + " "+ "inserito ordine sell " );
   }
}
 

Please don't post randomly in any section. Your question is not related to the section you posted.

MT4/mql4 has it's own section on the forum.

It has been move, so please don't create another topic.

 
moreor i have tried for hours and still couldn't find the problem on this code

I don't think you tried very hard.

  1.   bool trezzo = mainStoch_1 < signalStoch_1 &&
                           mainStoch_2 >= signalStoch_2 && mainStoch_1 > 80;
                           }                        <<<<<<<<<<<<<<< End of function.
       
       
     if (ariete && !presenteOrdineMercatoBarra() )  <<< 'if' - expressions are not allowed on a global scope     
       { 
       inserisciOrdineBuyEChiudiSell ( 0.1, "Buy" )
       }

    The compile error message showed the first problem (if you had clicked on it).

    If you had used the styler, the indenting would have easily shown you the first issue.

  2. If you had commented out (/* … */) the remaining functions, you would have easily seen the next problem by the error message.

    If you had used the styler, the indenting would have easily shown you the next issue.

    void OnTick(){
       ⋮   
     if (trezzo && !presenteOrdineMercatoBarra() )
       {
       inserisciOrdineSellEChiudiBuy ( 0.1 "Sell" )
       }
    
    vvvvvvvvvvvvvvvvvv What are those lines doing inside OnTick?
     
     input int magic = 1;                //Magic Number
    
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool presenteOrdineMercato(){ … }
    ^v^v^v^v^v^v^v^v^v What are those lines doing inside OnTick?