ontradetransaction function declarations are allowed on global,namespace or class scope only Help to solve this error I want it to function at indicator 2 not the whole chart thanks in advance

 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Indicator_2()
  {
   Indicator_2_Buy=0;
   Indicator_2_Sell=0;
   Indicator_2_Buy2=0;
   Indicator_2_Sell2=0;
   Indicator_2_Buy3=0;
   Indicator_2_Sell3=0;
   if(Indicator_2_switch==false)
     {
      Indicator_2_Buy=1;
      Indicator_2_Sell=1;
      Indicator_2_Buy2=1;
      Indicator_2_Sell2=1;
      Indicator_2_Buy3=1;
      Indicator_2_Sell3=1;
      return;
     }
   if(BarsCalculated(Indicator_2_Sequence)<1)
      return;

   double Rectangle_high_point[];
   double Rectangular_low_point[];
   int rectangleXXBUYNXXSELLNXX[];
   ArrayFree(Rectangle_high_point);
   ArrayFree(Rectangular_low_point);
   ArrayFree(rectangleXXBUYNXXSELLNXX);

   haveXXBUYNXXrectangleXX=false;
   haveXXSELLNXXrectangleXX=false;

   for(int ix=ObjectsTotal(0,0,OBJ_RECTANGLE)-1; ix>=0; ix--)
     {
      string NAMEX=ObjectName(0,ix,0,OBJ_RECTANGLE);
      double price1=MathMax(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1));
      double price2=MathMin(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1));

      ArrayResize(Rectangle_high_point,ArraySize(Rectangle_high_point)+1);
      ArrayResize(Rectangular_low_point,ArraySize(Rectangular_low_point)+1);
      ArrayResize(rectangleXXBUYNXXSELLNXX,ArraySize(rectangleXXBUYNXXSELLNXX)+1);

      Rectangle_high_point[ArraySize(Rectangle_high_point)-1]=price1;
      Rectangular_low_point[ArraySize(Rectangular_low_point)-1]=price2;
      rectangleXXBUYNXXSELLNXX[ArraySize(rectangleXXBUYNXXSELLNXX)-1]=(StringFind(NAMEX,"SSSR#S",0)!=-1)?0:1;

      if(iClose(Symbol(),0,0)>=price2&&iClose(Symbol(),0,0)<=price1)
        {
         if(StringFind(NAMEX,"SSSR#S",0)!=-1)
            Indicator_2_Buy=1;
         if(StringFind(NAMEX,"SSSR#R",0)!=-1)
            Indicator_2_Sell=1;
        }

      if(StringFind(NAMEX,"SSSR#R",0)!=-1)
        {
         haveXXSELLNXXrectangleXX=true;
         if(SELLSTOP==0||SELLSTOP>MathMax(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1)))
            SELLSTOP=MathMax(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1));
        }

      if(StringFind(NAMEX,"SSSR#S",0)!=-1)
        {
         haveXXBUYNXXrectangleXX=true;
         if(BUYSTOP==0||BUYSTOP<MathMin(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1)))
            BUYSTOP=MathMin(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1));
        }
     }

   bool Jump_out=false;

   if(ArraySize(Rectangle_high_point)!=0)
      for(int ix=0; ix<iBars(Symbol(),Indicator_4_Time_Frame); ix++)
        {
         for(int ix2=0; ix2<ArraySize(Rectangle_high_point); ix2++)
            if(iHigh(Symbol(),Indicator_4_Time_Frame,ix)>=Rectangular_low_point[ix2])
               if(iLow(Symbol(),Indicator_4_Time_Frame,ix)<=Rectangle_high_point[ix2])
                {
                  if(rectangleXXBUYNXXSELLNXX[ix2]==0)
                    {
                     Indicator_2_Sell2=1;

                     if(iClose(Symbol(),0,0)<=Rectangle_high_point[ix2]+Within_n_points_of_rectangle*_Point*CoefficientXX(Symbol()))
                        if(iClose(Symbol(),0,0)>=Rectangular_low_point[ix2]-Within_n_points_of_rectangle*_Point*CoefficientXX(Symbol()))
                           Indicator_2_Sell3=1;
                           
  
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- get transaction type as enumeration value 
   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
//--- if transaction is result of addition of the transaction in history
   if(type==TRADE_TRANSACTION_DEAL_ADD)
     {
      long     deal_type         =-1;
      long     deal_entry        =-1;
      double   deal_volume       =0.0;
      string   deal_symbol       ="";
      if(HistoryDealSelect(trans.deal))
        {
         deal_type         =HistoryDealGetInteger(trans.deal,DEAL_TYPE);
         deal_entry        =HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
         deal_volume       =HistoryDealGetDouble(trans.deal,DEAL_VOLUME);
         deal_symbol       =HistoryDealGetString(trans.deal,DEAL_SYMBOL);
        }
      else
         return;
      if(deal_entry==DEAL_ENTRY_OUT)
        {
         switch((int)deal_type)
           {
            case  DEAL_TYPE_BUY:
               m_trade.Buy(deal_volume,deal_symbol);
               break;
            case  DEAL_TYPE_SELL:
               m_trade.Sell(deal_volume,deal_symbol);
               break;
            default:
               break;
           }
        }
     }
  }
//+------------------------------------------------------------------+

                           
                           
                    }
                  else
                    {
                     Indicator_2_Buy2=1;

                     if(iClose(Symbol(),0,0)<=Rectangle_high_point[ix2]+Within_n_points_of_rectangle*_Point*CoefficientXX(Symbol()))
                        if(iClose(Symbol(),0,0)>=Rectangular_low_point[ix2]-Within_n_points_of_rectangle*_Point*CoefficientXX(Symbol()))
                           Indicator_2_Buy3=1;
                           
                      
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- get transaction type as enumeration value 
   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
//--- if transaction is result of addition of the transaction in history
   if(type==TRADE_TRANSACTION_DEAL_ADD)
     {
      long     deal_type         =-1;
      long     deal_entry        =-1;
      double   deal_volume       =0.0;
      string   deal_symbol       ="";
      if(HistoryDealSelect(trans.deal))
        {
         deal_type         =HistoryDealGetInteger(trans.deal,DEAL_TYPE);
         deal_entry        =HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
         deal_volume       =HistoryDealGetDouble(trans.deal,DEAL_VOLUME);
         deal_symbol       =HistoryDealGetString(trans.deal,DEAL_SYMBOL);
        }
      else
         return;
      if(deal_entry==DEAL_ENTRY_OUT)
        {
         switch((int)deal_type)
           {
            case  DEAL_TYPE_BUY:
               m_trade.Buy(deal_volume,deal_symbol);
               break;
            case  DEAL_TYPE_SELL:
               m_trade.Sell(deal_volume,deal_symbol);
               break;
            default:
               break;
           }
        }
     }
  }
//+------------------------------------------------------------------+
       
                    }
                   
                    
                    
                    
                  Jump_out=true;
                  break;
                 }
         if(Jump_out)
            break;
        }
        

            if(Rectangular_closing_switch)
     {
      if(Indicator_2_Buy2==1)
         if(Category_order_statistics(1,magic,"")!=2)
            deleteorder(1,magic,"");
            
      if(Indicator_2_Sell2==1)
         if(Category_order_statistics(0,magic,"")!=2)
            deleteorder(0,magic,"");
            
     
      {
            if(Sound){
               if(Indicator_2_Buy2==1)PlaySound("::Files\\SoundEA\\.wav");
            }
            
         }
         {
            if(Sound){
               if(Indicator_2_Sell2==1)PlaySound("::Files\\SoundEA\\.wav");
            }
            
         }
      }
       if(Indicator_2_Closeout_Switch)
     {
      if(Indicator_2_Buy==1)
         if(Category_order_statistics(1,magic,"")!=0)
            deleteorder(1,magic,"");

      if(Indicator_2_Sell==0)
         if(Category_order_statistics(0,magic,"")!=0)
            deleteorder(0,magic,"");
   
      {
            if(Sound){
               if(Indicator_2_Buy==1)PlaySound("::Files\\SoundEA\\.wav");
            }
            
         }
          {
            if(Sound){
               if(Indicator_2_Sell==1)PlaySound("::Files\\SoundEA\\.wav");
            }
            
         }
       }
        if(BUYSTOP!=0)
     {
      //BUYSTOP=BUYSTOP-Indicator_2_BUY_SL_to_increase_distance*_Point*CoefficientXX(Symbol());
      if(SymbolInfoDouble(Symbol(),SYMBOL_ASK)<BUYSTOP)
         Batch_Modification_TPSL(1,0,BUYSTOP,magic,"");
         
     }
     {
            if(Sound){
               if(SymbolInfoDouble(Symbol(),SYMBOL_ASK)>BUYSTOP)PlaySound("::Files\\SoundEA\\AdjustTP.wav");
            }
            
         }

   if(SELLSTOP!=0)
     {
      //SELLSTOP=SELLSTOP+Indicator_2_SELL_SL_to_increase_distance*_Point*CoefficientXX(Symbol());
      if(SymbolInfoDouble(Symbol(),SYMBOL_BID)>SELLSTOP)
         Batch_Modification_TPSL(0,0,SELLSTOP,magic,"");
         
     }
      {
            if(Sound){
               if(SymbolInfoDouble(Symbol(),SYMBOL_BID)<SELLSTOP)PlaySound("::Files\\SoundEA\\AdjustTP.wav");
            }
            
         }


   if(haveXXBUYNXXrectangleXX==false)
     {
      Indicator_2_Buy=1;
      Indicator_2_Buy2=1;
      Indicator_2_Buy3=1;
     }

   if(haveXXSELLNXXrectangleXX==false)
     {
      Indicator_2_Sell=1;
      Indicator_2_Sell2=1;
      Indicator_2_Sell3=1;
     }
  }
 
Thuto Lenity Ramosesane:

I fixed the error for you, but you should check the code. You've got the error because ontradetransaction function declarations are allowed on global, namespace or class scope only.

You need to declare every identifier.

Check your brackets, create body's of code.

Write operators when they're expected.

Declare the Jump_out variable globaly.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Indicator_2()
  {
   Indicator_2_Buy=0;
   Indicator_2_Sell=0;
   Indicator_2_Buy2=0;
   Indicator_2_Sell2=0;
   Indicator_2_Buy3=0;
   Indicator_2_Sell3=0;
   if(Indicator_2_switch==false)
     {
      Indicator_2_Buy=1;
      Indicator_2_Sell=1;
      Indicator_2_Buy2=1;
      Indicator_2_Sell2=1;
      Indicator_2_Buy3=1;
      Indicator_2_Sell3=1;
      return;
     }
   if(BarsCalculated(Indicator_2_Sequence)<1)
      return;

   double Rectangle_high_point[];
   double Rectangular_low_point[];
   int rectangleXXBUYNXXSELLNXX[];
   ArrayFree(Rectangle_high_point);
   ArrayFree(Rectangular_low_point);
   ArrayFree(rectangleXXBUYNXXSELLNXX);

   haveXXBUYNXXrectangleXX=false;
   haveXXSELLNXXrectangleXX=false;

   for(int ix=ObjectsTotal(0,0,OBJ_RECTANGLE)-1; ix>=0; ix--)
     {
      string NAMEX=ObjectName(0,ix,0,OBJ_RECTANGLE);
      double price1=MathMax(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1));
      double price2=MathMin(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1));

      ArrayResize(Rectangle_high_point,ArraySize(Rectangle_high_point)+1);
      ArrayResize(Rectangular_low_point,ArraySize(Rectangular_low_point)+1);
      ArrayResize(rectangleXXBUYNXXSELLNXX,ArraySize(rectangleXXBUYNXXSELLNXX)+1);

      Rectangle_high_point[ArraySize(Rectangle_high_point)-1]=price1;
      Rectangular_low_point[ArraySize(Rectangular_low_point)-1]=price2;
      rectangleXXBUYNXXSELLNXX[ArraySize(rectangleXXBUYNXXSELLNXX)-1]=(StringFind(NAMEX,"SSSR#S",0)!=-1)?0:1;

      if(iClose(Symbol(),0,0)>=price2&&iClose(Symbol(),0,0)<=price1)
        {
         if(StringFind(NAMEX,"SSSR#S",0)!=-1)
            Indicator_2_Buy=1;
         if(StringFind(NAMEX,"SSSR#R",0)!=-1)
            Indicator_2_Sell=1;
        }

      if(StringFind(NAMEX,"SSSR#R",0)!=-1)
        {
         haveXXSELLNXXrectangleXX=true;
         if(SELLSTOP==0||SELLSTOP>MathMax(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1)))
            SELLSTOP=MathMax(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1));
        }

      if(StringFind(NAMEX,"SSSR#S",0)!=-1)
        {
         haveXXBUYNXXrectangleXX=true;
         if(BUYSTOP==0||BUYSTOP<MathMin(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1)))
            BUYSTOP=MathMin(ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,0),ObjectGetDouble(0,NAMEX,OBJPROP_PRICE,1));
        }
     }

   bool Jump_out=false;

   if(ArraySize(Rectangle_high_point)!=0)
      for(int ix=0; ix<iBars(Symbol(),Indicator_4_Time_Frame); ix++)
        {
         for(int ix2=0; ix2<ArraySize(Rectangle_high_point); ix2++)
            if(iHigh(Symbol(),Indicator_4_Time_Frame,ix)>=Rectangular_low_point[ix2])
               if(iLow(Symbol(),Indicator_4_Time_Frame,ix)<=Rectangle_high_point[ix2])
                {
                  if(rectangleXXBUYNXXSELLNXX[ix2]==0)
                    {
                     Indicator_2_Sell2=1;

                     if(iClose(Symbol(),0,0)<=Rectangle_high_point[ix2]+Within_n_points_of_rectangle*_Point*CoefficientXX(Symbol()))
                        if(iClose(Symbol(),0,0)>=Rectangular_low_point[ix2]-Within_n_points_of_rectangle*_Point*CoefficientXX(Symbol()))
                           Indicator_2_Sell3=1;
                     }
           }
     }
}    
  
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- get transaction type as enumeration value 
   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
//--- if transaction is result of addition of the transaction in history
   if(type==TRADE_TRANSACTION_DEAL_ADD)
     {
      long     deal_type         =-1;
      long     deal_entry        =-1;
      double   deal_volume       =0.0;
      string   deal_symbol       ="";
      if(HistoryDealSelect(trans.deal))
        {
         deal_type         =HistoryDealGetInteger(trans.deal,DEAL_TYPE);
         deal_entry        =HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
         deal_volume       =HistoryDealGetDouble(trans.deal,DEAL_VOLUME);
         deal_symbol       =HistoryDealGetString(trans.deal,DEAL_SYMBOL);
        }
      else
         return;
      if(deal_entry==DEAL_ENTRY_OUT)
        {
         switch((int)deal_type)
           {
            case  DEAL_TYPE_BUY:
               m_trade.Buy(deal_volume,deal_symbol);
               break;
            case  DEAL_TYPE_SELL:
               m_trade.Sell(deal_volume,deal_symbol);
               break;
            default:
               break;
           }
        }
     }
  }
//+------------------------------------------------------------------+

                           
                           
                    }
                  else
                    {
                     Indicator_2_Buy2=1;

                     if(iClose(Symbol(),0,0)<=Rectangle_high_point[ix2]+Within_n_points_of_rectangle*_Point*CoefficientXX(Symbol()))
                        if(iClose(Symbol(),0,0)>=Rectangular_low_point[ix2]-Within_n_points_of_rectangle*_Point*CoefficientXX(Symbol()))
                           Indicator_2_Buy3=1;
                           
                      
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- get transaction type as enumeration value 
   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
//--- if transaction is result of addition of the transaction in history
   if(type==TRADE_TRANSACTION_DEAL_ADD)
     {
      long     deal_type         =-1;
      long     deal_entry        =-1;
      double   deal_volume       =0.0;
      string   deal_symbol       ="";
      if(HistoryDealSelect(trans.deal))
        {
         deal_type         =HistoryDealGetInteger(trans.deal,DEAL_TYPE);
         deal_entry        =HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
         deal_volume       =HistoryDealGetDouble(trans.deal,DEAL_VOLUME);
         deal_symbol       =HistoryDealGetString(trans.deal,DEAL_SYMBOL);
        }
      else
         return;
      if(deal_entry==DEAL_ENTRY_OUT)
        {
         switch((int)deal_type)
           {
            case  DEAL_TYPE_BUY:
               m_trade.Buy(deal_volume,deal_symbol);
               break;
            case  DEAL_TYPE_SELL:
               m_trade.Sell(deal_volume,deal_symbol);
               break;
            default:
               break;
           }
        }
     }
  }
//+------------------------------------------------------------------+
       
                    }
                   
                    
                    
                    
                  Jump_out=true;
                  break;
                 }
         if(Jump_out)
            break;
        }
        

            if(Rectangular_closing_switch)
     {
      if(Indicator_2_Buy2==1)
         if(Category_order_statistics(1,magic,"")!=2)
            deleteorder(1,magic,"");
            
      if(Indicator_2_Sell2==1)
         if(Category_order_statistics(0,magic,"")!=2)
            deleteorder(0,magic,"");
            
     
      {
            if(Sound){
               if(Indicator_2_Buy2==1)PlaySound("::Files\\SoundEA\\.wav");
            }
            
         }
         {
            if(Sound){
               if(Indicator_2_Sell2==1)PlaySound("::Files\\SoundEA\\.wav");
            }
            
         }
      }
       if(Indicator_2_Closeout_Switch)
     {
      if(Indicator_2_Buy==1)
         if(Category_order_statistics(1,magic,"")!=0)
            deleteorder(1,magic,"");

      if(Indicator_2_Sell==0)
         if(Category_order_statistics(0,magic,"")!=0)
            deleteorder(0,magic,"");
   
      {
            if(Sound){
               if(Indicator_2_Buy==1)PlaySound("::Files\\SoundEA\\.wav");
            }
            
         }
          {
            if(Sound){
               if(Indicator_2_Sell==1)PlaySound("::Files\\SoundEA\\.wav");
            }
            
         }
       }
        if(BUYSTOP!=0)
     {
      //BUYSTOP=BUYSTOP-Indicator_2_BUY_SL_to_increase_distance*_Point*CoefficientXX(Symbol());
      if(SymbolInfoDouble(Symbol(),SYMBOL_ASK)<BUYSTOP)
         Batch_Modification_TPSL(1,0,BUYSTOP,magic,"");
         
     }
     {
            if(Sound){
               if(SymbolInfoDouble(Symbol(),SYMBOL_ASK)>BUYSTOP)PlaySound("::Files\\SoundEA\\AdjustTP.wav");
            }
            
         }

   if(SELLSTOP!=0)
     {
      //SELLSTOP=SELLSTOP+Indicator_2_SELL_SL_to_increase_distance*_Point*CoefficientXX(Symbol());
      if(SymbolInfoDouble(Symbol(),SYMBOL_BID)>SELLSTOP)
         Batch_Modification_TPSL(0,0,SELLSTOP,magic,"");
         
     }
      {
            if(Sound){
               if(SymbolInfoDouble(Symbol(),SYMBOL_BID)<SELLSTOP)PlaySound("::Files\\SoundEA\\AdjustTP.wav");
            }
            
         }


   if(haveXXBUYNXXrectangleXX==false)
     {
      Indicator_2_Buy=1;
      Indicator_2_Buy2=1;
      Indicator_2_Buy3=1;
     }

   if(haveXXSELLNXXrectangleXX==false)
     {
      Indicator_2_Sell=1;
      Indicator_2_Sell2=1;
      Indicator_2_Sell3=1;
     }
  }

Hope this was somewhat helpfull

Reason: