unexpected end to program and unbalanced parentheses

Tommy Russell - LMR  
Hi all, I am new to coding and am having some issues with this code. I have adapted this code from a friend and tried to make it work with my parameters, but the code does not seem to be working for me. Does anyone see what's wrong with it???
//--- input parameters
input int     StopLoss=30;
input int     TakeProfit=60;
input int     ADX_Period=20;
input int     MA_Period=20;
input int     EA_Magic=12345;
input double  Adx_Min=22.0;
input double  Lot=0.1;
//--- Other parameters
int adxHandle; // handle for our ADX indicator
int maHandle; // handle for our Moving Average indicator
double plsDI[],minDI[],adxVal[]; // Dynamic arrays to hold the values of +DI, -DI and ADX values for each bar
double maVal[]; // Dynamic array to hold the values of Moving Average for each bars
double p_close; //Variable used to store the close value of a bar
int STP, TKP; //To be used for Stop Loss & Take Profit values
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Get handle for ADX indicator
   adxHandle=iADX(NULL,0,ADX_Period);
//--- Get handle for Moving Average indicator
   maHandle=iMA(_Symbol,_Period,MA_Period,0,MODE_EMA,PRICE_CLOSE);
//---what if handle returns invalid handle
   if(adxHandle<0 || maHandle<0)
     {
      Alert("Error Creating Handles for indicators - error: ",GetLastError(),"!!");
     }
//---Let us handle currency pairs with 5 or 3 digit prices instead of 4
   STP = StopLoss;
   TKP = TakeProfit;
   if(_Digits==5 || _Digits==3)
     {
      STP = STP*10;
      TKP = TKP*10;
     }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- Release our indicator handles
   IndicatorRelease(adxHandle);
   IndicatorRelease(maHandle);

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()

  {
//--- Do we have enough bars to work with
   if(Bars(_Symbol,_Period)<100) // if total bars is less then 100
     {
      Alert("We have less then 100 bars, EA will now exit!!");
      return;
     }
//--- We will use the Old_Time variable to serve the bar time.
//---At each OnTick execution we will check the current bar time with the saved one.
//---If the bar time isn't equal to the saved time, it indicates that we have a new tick.
   static datetime Old_Time;
   datetime New_time[1];
   bool IsNewBar=false;

//---Copying the last bar time to the element New_Time [0]
   int copied=CopyTime(_Symbol,_Period,0,1,New_Time);
   if(copied>0) // the data has been copied successfully
     {
      if(Old_Time!=New_Time[0]) // if old time isn't equal to new bar time
        {
         IsNewBar=true; // if it isn't a first call, the new bar has appeared
         if(MQLInfoInteger(MQL5_DEBUGGING))
            Print("We have the new bar here ",New_Time[0]," old time was ",Old_Time);
         Old_Time=New_Time[0]; // saving bar time
        }
      else
        {
         Alert("Error in copying historical times data, error =",GetLastError());
         ResetLastError();
         return;
        }
      //--- EA Should only check for new trade if we have a new bar
      if(IsNewBar==false)
        {
         return;
        }
      //--- Do we have enough bars to work with
      int Mybars=Bars(_Symbol,_Period);
      if(Mybars<100) // if total bars is less then 100 bars
        {
         Alert("We have less than 100 bars, EA will now exit!!");
         return;
        }

      //--- Define some MQL5 Structures we will use for our trade
      MqlTick latest_price;      // To be used for getting recent/latest price quotes
      MqlTradeRequest mrequest;  // To be used for sending our trade requests
      MqlTradeResult mresult;    // To be used to gt our trade results
      MqlRates mrate[];          // To be used to store the prices, volumes and spread of each bar
      ZeroMemory(mrequest);      // Initialization of mrequest structure

      bool ArraySetAsSeries(
         void array[], // array by reference
         bool set      // true denotes reverse order of indexing
      );

      ///--- Get the last price quote using the MQL5 MqlTick Structure
      if(!SymbolInfoTick(_Symbol,Latest_price))
        {
         Alert("Error getting the latest price quote - error:",GetLastError(),"!!");
         return;
        }

      ///--- Get the details of the latest 3 bars
      if(CopyRates(_Symbol,_Period,0,3,mrate)<0)
        {
         Alert("Error copying rates/history data - error:",GetLastError(),"!!");
         return;
        }

      int CopyRates(
         string           symbol_name,  // symbol name
         ENUM_TIMEFRAMES  timeframe,    // period
         int              start_pos,    // start position
         int              count,        // data count to copy
         MqlRates         rates_array[] // target array to copy
      );

      int CopyBuffer(
         int     indicator_handle,  // indicator handle
         int     buffer_num,        // indicator buffer number
         int     start_pos,         // start position
         int     count,             // amount to copy
         double  buffer[]           // target array to copy
      );

      ///--- Copy the new values of our indicators to buffers (arrays) using the handle
      if(CopyBuffer(adxHandle,0,0,3,adxVal)<0 || CopyBuffer(adxHandle,1,0,3,plsDI)<0
         || CopyBuffer(adxHandle,2,0,3,minDI)<0)
        {
         Alert("Error copying ADX indicator Buffers - error:", GetLastError(),"!!");
         return;
        }
      if(CopyBuffer(maHandle,0,0,3,maValue)<0)
        {
         Alert("Error copying Moving Average indicator buffer - error:", GetLastError());
         return;
        }

      ///--- We have no errors, so continue
      ///--- Do we have positions opened already?
      bool Buy_opened=false;   // variable to hold the result of buy opened position
      bool Sell_opened=false;  // varriable to hold the result of sell opened position

      if(PositionSelect(_Symbol) ==true)   // we have an opened position
        {
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
           {
            Buy_opened = true;  // it is a buy
           }
         else
            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
              {
               Sell_opened = true;  // it is a sell
              }
        }

      bool positionSelect(
         string symbol // symbol name
      );

      long PositionGetInteger(
         ENUM_POSITION_PROPERTY property_id  // Property identifier
      );

      ///--- Copy the bar close price for the previous bar prior to the current bar, that is Bar 1

      p_close=mrate[1].close; // bar 1 close price

      /*
         1. Check for a long/Buy Setup : MA-20 increasing upwards,
         previous price close above it, ADX > 20, +DI > -DI
      */
      //--- Declare bool type variables to hold our buy conditions
      bool Buy_Condition_1 = (maVal[0]>maVal[1]) && (maVal[1]>maVal[2]); // MA-20 increasing upwards
      bool Buy_Condition_2 = (p_close > maVal[1]);                       // Previous price closed above MA-20
      bool Buy_Condition_3 = (adxVal[0]>Adx_Min);                        // Current ADX value greater than minimum value (22)
      bool Buy_Condition_4 = (plsDI[0]>minDI[0]);                        // +DI greater than -DI

      //--- Putting all together
      if(Buy_Condition_1 && Buy_Condition_2)
        {
         if(Buy_Condition_3 && Buy_Condition_4)
           {
            // any opened buy position?
            if(Buy_opened)
              {
               Alert("We already have a Buy Position!!!");
               return;
              }

            mrequest.action = TRADE_ACTION_DEAL;                                   // immediate order execution
            mrequest.price = NormalizeDouble(latest_price.ask,_Digits);            // latest ask price
            mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits);  // Stop Loss
            mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits);  // Take Profit
            mrequest.symbol = _Symbol;                                             // Currency pair
            mrequest.volume = lot;                                                 // Number of lots to trade
            mrequest.magic = EA_Magic                                              // Order Magic Number
                             mrequest.type = ORDER_TYPE_BUY;                                        // Buy order
            mrequest.type_filling = ORDER_FILLING_FOK;                             // Order execution type
            mrequest.deviation=100;                                                // Deviation from current price
            //--- send order
            OrderSend(mrequest,mresult);

            bool OrderSend(
               MqlTradeRequest& request // query structure
               MqlTradeResult& result   // structure of the answer
            );

            // get the result code
            if(mresult.retcode==10009 || mresult.retcode==10008) // Request is completed or order placed
              {
               Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
              }
            else
              {
               Alert("The Buy order request could not be completed -error:",GetLastError());
               ResetLastError();
               return;
              }

            /*
              1. Check for a Short/Sell Setup : MA-20 decreasing downwards,
              previous price close below it, ADX > 20, -DI > +DI
            */
            //--- Declare bool type variables to hold our buy conditions
            bool Sell_Condition_1 = (maVal[0]<maVal[1]) && (maVal[1]<maVal[2]); // MA-20 increasing upwards
            bool Sell_Condition_2 = (p_close < maVal[1]);                       // Previous price closed above MA-20
            bool Sell_Condition_3 = (adxVal[0]>Adx_Min);                        // Current ADX value greater than minimum value (22)
            bool Sell_Condition_4 = (plsDI[0]<minDI[0]);

            //--- Putting all together
            if(Sell_Condition_1 && Sell_Condition_2)
              {
               if(Sell_Condition_3 && Sell_Condition_4)
                 {
                  // any opened sell position?
                  if(Sell_opened)
                    {
                     Alert("We already have a Sell Position!!!");
                     return;
                    }
                  if(mresult.retcode==10009 || mresult.retcode==10008) // Request is completed or order placed
                    {
                     Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
                    }
                  else
                    {
                     Alert("The Buy order request could not be completed -error:",GetLastError());
                     ResetLastError();
                     return;
                    }
                  mrequest.action = TRADE_ACTION_DEAL;                                   // Immediate order execution
                  mrequest.price = NormalizeDouble(latest_price.bid,_Digits);            // Latest bid price
                  mrequest.sl = NormalizeDouble(latest_price.bid - STP*_Point,_Digits);  // Stop Loss
                  mrequest.tp = NormalizeDouble(latest_price.bid + TKP*_Point,_Digits);  // Take Profit
                  mrequest.symbol = _Symbol;                                             // Currency pair
                  mrequest.volume = lot;                                                 // Number of lots to trade
                  mrequest.magic = EA_Magic                                              // Order Magic Number
                                   mrequest.type = ORDER_TYPE_SELL;                                       // Sell order
                  mrequest.type_filling = ORDER_FILLING_FOK;                             // Order execution type
                  mrequest.deviation=100;                                                // deviation from current price
                  //--- send order
                  OrderSend(mrequest,mresult);

                  if(mresult.retcode==10009 || mresult.retcode==10008) // Request is completed or order placed
                    {
                     Alert("A Sell order has been successfully placed with Ticket#:",mresult.order,"!!");
                    }
                  else
                    {
                     Alert("The sell order request could not be completed -error:",GetLastError());
                     ResetLastError();
                     return;
                    }

                  return;
                 }

              }
            //+------------------------------------------------------------------+
            //| Trade function                                                   |
            //+------------------------------------------------------------------+
            void OnTrade()
              {
               //---

              }
            //+------------------------------------------------------------------+
            //| Tester function                                                  |
            //+------------------------------------------------------------------+
            double OnTester()
              {
               //---
               double ret=0.0;
               //---

               //---
               return(ret);
              }
            //+------------------------------------------------------------------+

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

            //+------------------------------------------------------------------+
            //| TesterInit function                                              |
            //+------------------------------------------------------------------+
            void OnTesterInit()
              {
               //---

              }
            //+------------------------------------------------------------------+
            //| TesterPass function                                              |
            //+------------------------------------------------------------------+
            void OnTesterPass()
              {
               //---

              }
            //+------------------------------------------------------------------+
            //| TesterDeinit function                                            |
            //+------------------------------------------------------------------+
            void OnTesterDeinit()
              {
               //---

              }
            //+------------------------------------------------------------------+
            //| ChartEvent function                                              |
            //+------------------------------------------------------------------+
            void OnChartEvent(const int id,
                              const long &lparam,
                              const double &dparam,
                              const string &sparam)
              {
               //---

              }
            //+------------------------------------------------------------------+
            //| BookEvent function                                               |
            //+------------------------------------------------------------------+
            void OnBookEvent(const string &symbol)
              {
               //---

              }
            //+------------------------------------------------------------------+

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

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

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

            //+------------------------------------------------------------------+
            
Files:
Fernando Carreiro  
TommyRussell-LMR: Hi all, I am new to coding and am having some issues with this code. I have adapted this code from a friend and tried to make it work with my parameters, but the code does not seem to be working for me. Does anyone see what's wrong with it???

I think you should ask your friend for some help with your coding. There are just too many things wrong with it.

  • In several places you have copy/pasted function declarations into the middle of the procedural code, rendering it useless.
  • You have several closing braces missing.
  • And after "fixing" the above you still have another 22 errors and 4 warnings.
'Trend_Trade_Bot_V2.mq5'        Trend_Trade_Bot_V2.mq5  1       1
'New_Time' - undeclared identifier      Trend_Trade_Bot_V2.mq5  78      44
'CopyTime' - no one of the overloads can be applied to the function call        Trend_Trade_Bot_V2.mq5  78      15
could be one of 3 function(s)   Trend_Trade_Bot_V2.mq5  78      15
   built-in: int CopyTime(const string,ENUM_TIMEFRAMES,int,int,datetime&[])     Trend_Trade_Bot_V2.mq5  78      15
   built-in: int CopyTime(const string,ENUM_TIMEFRAMES,datetime,int,datetime&[])        Trend_Trade_Bot_V2.mq5  78      15
   built-in: int CopyTime(const string,ENUM_TIMEFRAMES,datetime,datetime,datetime&[])   Trend_Trade_Bot_V2.mq5  78      15
'New_Time' - undeclared identifier      Trend_Trade_Bot_V2.mq5  81      20
'0' - some operator expected    Trend_Trade_Bot_V2.mq5  81      29
'(' - unbalanced left parenthesis       Trend_Trade_Bot_V2.mq5  81      9
']' - unexpected token  Trend_Trade_Bot_V2.mq5  81      30
')' - unexpected token  Trend_Trade_Bot_V2.mq5  81      31
'MQL5_DEBUGGING' - cannot convert enum  Trend_Trade_Bot_V2.mq5  84      28
   built-in: int MQLInfoInteger(ENUM_MQL_INFO_INTEGER)  Trend_Trade_Bot_V2.mq5  84      28
'New_Time' - undeclared identifier      Trend_Trade_Bot_V2.mq5  85      47
'0' - some operator expected    Trend_Trade_Bot_V2.mq5  85      56
']' - unexpected token  Trend_Trade_Bot_V2.mq5  85      57
'New_Time' - undeclared identifier      Trend_Trade_Bot_V2.mq5  86      19
'0' - some operator expected    Trend_Trade_Bot_V2.mq5  86      28
'else' - illegal 'else' without matching 'if'   Trend_Trade_Bot_V2.mq5  88      7
'Latest_price' - undeclared identifier  Trend_Trade_Bot_V2.mq5  122     34
'Latest_price' - variable expected      Trend_Trade_Bot_V2.mq5  122     34
   built-in: bool SymbolInfoTick(const string,MqlTick&) Trend_Trade_Bot_V2.mq5  122     34
'maValue' - undeclared identifier       Trend_Trade_Bot_V2.mq5  159     36
'CopyBuffer' - no one of the overloads can be applied to the function call      Trend_Trade_Bot_V2.mq5  159     10
could be one of 3 function(s)   Trend_Trade_Bot_V2.mq5  159     10
   built-in: int CopyBuffer(int,int,int,int,double&[])  Trend_Trade_Bot_V2.mq5  159     10
   built-in: int CopyBuffer(int,int,datetime,int,double&[])     Trend_Trade_Bot_V2.mq5  159     10
   built-in: int CopyBuffer(int,int,datetime,datetime,double&[])        Trend_Trade_Bot_V2.mq5  159     10
'lot' - undeclared identifier   Trend_Trade_Bot_V2.mq5  222     31
'type' - some operator expected Trend_Trade_Bot_V2.mq5  224     39
expression has no effect        Trend_Trade_Bot_V2.mq5  224     46
return value of 'OrderSend' should be checked   Trend_Trade_Bot_V2.mq5  228     13
'lot' - undeclared identifier   Trend_Trade_Bot_V2.mq5  283     37
'type' - some operator expected Trend_Trade_Bot_V2.mq5  285     45
expression has no effect        Trend_Trade_Bot_V2.mq5  285     52
return value of 'OrderSend' should be checked   Trend_Trade_Bot_V2.mq5  289     19
22 errors, 4 warnings           23      5

And besides the compiler errors and warnings, there are still several logic problems with it.

The whole thing needs to be cleaned up.

Reason: