True strength index convergence and divergence expert advisor error

 
//+------------------------------------------------------------------+

//+---//+------------------------------------------------------------------+
//|                                                    TSI_CD EA.mq5
//|                                                    Kamau Muchiri
//|                                             https://www.mql5.com
//+------------------------------------------------------------------+
#property copyright "Kamau Muchiri"
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- input parameters
input int      Stoploss = 46; //Stoploss in pips
input int      TakeProfit = 96; //Takeprofit in pips
input int      MA_Period1 = 12; // Short term MA period
input int      MA_Period2 = 54; //Long term MA period
input int      ema1 = 9; //First MA smoothing of TSI
input int      ema2 = 5; //Second smoothing of TSI
input int      sMAp = 5; //Signal line MA period
input ENUM_MA_METHOD MAmode = MODE_EMA; //M0ving Average type
input int Magic = 12345; // EA Magic number
input double   Lotsize = 0.05; //Lotsize
    
//Other Global parameters
int TSICDHandle; //Handle for our TSICD indicator
int maHandle1; // Handle for our first MA
int maHandle2, // Handle for our second MA
    TSI_mline[], TSI_sline[]; //Arrays to hold the values of the Mainline and Signal line from TSI
int   maVal1[], maVal2[]; //Arrays to hold the values of moving averages
double p_close; //Variable to hold the values the closing price
int STP, TKP; //Variables to store our Stoploss and Takeprofit

//+------------------------------------------------------------------+//
//Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//....Getting the indicator handles
   TSICDHandle = (iCustom(_Symbol, _Period, "TSI_CD", ema1, ema2, sMAp, MAmode));
   maHandle1 = (iMA(_Symbol, _Period, MA_Period1, 0, MODE_EMA, PRICE_CLOSE));
   maHandle2 = (iMA(_Symbol, _Period, MA_Period2, 0, MODE_EMA, PRICE_CLOSE));
//Check to see if valid Handles are returned
   if((TSICDHandle < 0) || (maHandle1 < 0) || (maHandle2 < 0))
     {
      Alert("Error creating handles for indicators-error:", GetLastError(), " !!");
     }
//......Standardise   the currency digits for different pairs
   STP = Stoploss;
   TKP = TakeProfit;
   if(_Digits == 5 || _Digits == 3)
     {
      STP = STP * 10;
      TKP = TKP * 10;
     }
     {
      //....Checking the adequecy of the number of Bars in History
      if(Bars(_Symbol, _Period) < 500) //If the bars are less than 500
        {
        }
     }
   Alert("We have less than 500 bars,EA will now exit");
   return(0);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
     {
        {
         //---Releasing indicator handles
         IndicatorRelease(TSICDHandle);
         IndicatorRelease(maHandle1);
         IndicatorRelease(maHandle2);
         return;
        }
     }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   void OnTick(){
      //---Check if we have a new bar
      static datetime Oldtime;// Save data about the time  of the candlestick of the previous tick
      datetime Newtime[1]; //Save data about time of the candlestick of the current tick
      bool IsNewBar = false; // Compare Oldtime with Newtime
      int copied = (CopyTime(_Symbol, _Period, 0, 1, Newtime));
      if(copied > 0)
        {
         if(Oldtime != Newtime[0])
           {
            IsNewBar = true; //If New time and Oldtime are different,there is a newbar
            Oldtime = Newtime[0];
           }
        }
      if(Oldtime == Newtime[0])
        {
         Alert("Error in copying Historical time data,error= ", GetLastError());
         ResetLastError();
         return;
        }
      if(IsNewBar == false)
        {
         return;
        }
      // Checking the number of bars again
      int MyBars = (Bars(_Symbol, _Period));
      if(MyBars < 500)
        {
         Alert("We have less than 500 Bars,EA will now Exit!!");
         return;
        }
      //...Defining some MQL5 structures to be used for our trades
      MqlTick latest_price;//To be used to get the letest information about the larest price
      MqlTradeRequest mrequest;// To be used for sending out trade requests
      MqlTradeResult mresult; //To be used for getting trade results
      MqlRates mrate[];//To be used to store data about each bar
      ZeroMemory(mrequest); // To be used for the initialisation of mrequest structure
      //Setting out Arrays to the ArraySetAsSeries Flag
      ArraySetAsSeries(mrate, true);
      ArraySetAsSeries(TSI_mline, true);
      ArraySetAsSeries(TSI_sline, true);
      ArraySetAsSeries(maVal1, true);
      ArraySetAsSeries(maVal2, true);
      //...Getting and Checking if we got the latest price quote using the mqlTick structure
      if(!SymbolInfoTick(_Symbol, latest_price))
        {
         Alert("Error getting the latest price quote-Error: ", GetLastError(), "!!");
         return;
        }
      //Getting and Checking the details about the latest 3 Bars
      if(CopyRates(_Symbol, _Period, 0, 3, mrate) < 0)
        {
         Alert("Error copying rates data-error: ", GetLastError(), " !!");
         return;
        }
      //...Copying and Checking the new values of the indicatorsto buffers(arrays) using the handles
      if(CopyBuffer(TSICDHandle, 1, 0, 3, TSI_mline) < 0)
        {
         if(CopyBuffer(TSICDHandle, 0 2, 0, 3, TSI_mline) < 0)
           {
            Alert("Error copying the TSICD indicator buffers -error:  ", GetLastError(), " !!");
            return;
           }
        }
      if(CopyBuffer(maHandle1, 0, 0, 0, 3, maVal1) < 0)
        {
           {
            if(CopyBuffer(maHandle2, 0, 0, 3, maVal2) < 0)
              {
               Alert("Error copying the TSICD indicator buffers -error:  ", GetLastError(), " !!");
               return;
              }
           }
        }
      //....Checking for the presence of open positions
      bool Buy_opened = false; //Variable to store information whether a buy is open or not
      bool Sell_opened = false; //Variable to store information whether a sell is open or no
      if(PositionSelect(_Symbol) == true)
        {
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
           {
            Buy_opened = true;
           }
        }
      else
        {
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
           {
            Sell_opened = true;
           }
        }
      // Copy the bar close price for the previous bar prior to the current bar, that is bar 1
      p_close = mrate[1].close;               //Check for conditions for our Buy entry
      bool Buycondition1 = ((TSI_mline[0] > TSI_sline[0]) && (TSI_mline[1] < TSI_sline[1]) && (p_close > maVal2[1]));
      bool Buycondition2 = ((maVal1[1] - maVal2[1]) > (maVal1[2] - maVal2[2]));
      if(Buycondition1 && Buycondition2)
        {
         if(Buy_opened)
           {
            Alert("We already have a buy position");
            return;
           }
        }
      mrequest.action = TRADE_ACTION_DEAL;
      mrequest.price = NormalizeDouble(latest_price.ask, _Digits);
      mrequest.sl = NormalizeDouble(latest_price.ask - STP * _Point, _Digits);
      mrequest.tp = NormalizeDouble(latest_price.ask + TKP * _Point, _Digits);
      mrequest.symbol = _Symbol;
      mrequest.volume = Lotsize;
      mrequest.magic =  EA_Magic;
      mrequest.type = ORDER_TYPE_BUY;
      mrequest.type_filling = ORDER_FILLING_FOK;
      mrequest.deviation = 100;
      //Sending Buy order
      bool buyorder = OrderSend(mrequest, mresult);
      //Getting the result code
      if(mresult.retcode == 10009 || mresult.retcode == 10000)
        {
         Alert("A buy order has been successfully placed with Tickets# : ", mresult.order, "!!");
        }
      else
        {
         Alert("A buy order could not be placed-Error: ", GetLastError());
         ResetLastError();
         return;
        }
      //....Check for conditions for our Sell entry
      bool Sellcondition1 = ((TSI_mline[0] < TSI_sline[0]) && (TSI_mline[1] > TSI_sline[1]) && (p_close < maVal2[1]));
      bool Sellcondition2 = ((maVal2[1] - maVal1[1]) > (maVal2[2] - maVal1[2]));
      if(Sellcondition1 && Sellcondition2)
        {
         if(Sell_opened)
           {
            Alert("We already have a sell position");
            return;
           }
        }
      mrequest.action = TRADE_ACTION_DEAL;
      mrequest.price = NormalizeDouble(latest_price.bid, _Digits);
      mrequest.sl = NormalizeDouble(latest_price.bid - STP * _Point, _Digits);
      mrequest.tp = NormalizeDouble(latest_price.bid + TKP * _Point, _Digits);
      mrequest.symbol = _Symbol;
      mrequest.volume = Lotsize;
      mrequest.magic = EA_Magic;
      mrequest.type = ORDER_TYPE_SELL;
      mrequest.type_filling = ORDER_FILLING_FOK;
      mrequest.deviation = 100;
      //Sending Sell order
      buyorder = OrderSend(mrequest, mresult);
      //Getting the result code
      if(mresult.retcode == 10009 || mresult.retcode == 10000)
        {
         Alert("A sell order has been successfully placed with Tickets# : ", mresult.order, "!!");
        }
      else
        {
           {
            Alert("A sell order could not be placed-Error: ", GetLastError());
            ResetLastError();
           }
         return;
        }
     }
  }
Hi there?This code on True Strength Index Convergence and Divergence Expert Advisor gives out 1 error.
Error:OnTick function can only be declared on a global,namaespace or class only.Please how I can fix this error? 



 
void OnDeinit(const int reason)
  { // Where is the closing parenthesis?
     {
        {
         //---Releasing indicator handles
         IndicatorRelease(TSICDHandle);
         IndicatorRelease(maHandle1);
         IndicatorRelease(maHandle2);
         return;
        }
     }
 
Thanks a lot!!!!