PROBLEM WITH: end_of_program - unbalanced left parenthesis

 

This is my first EA, and I keep getting the  '\end_of_program - unbalanced left parenthesis' error message when compiling, but I can't find any missing parenthesis.  It's based on MACD Sample.  Please help if you can.  Thanks!!!- ----

 //| expert initialization function                                   |
//+------------------------------------------------------------------+

// Defining variables

extern double TakeProfit = 20;
extern double Lots = 1;
extern double Stop = 20;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent, SignalPrevious;
double CCI0, CCI1, CCI2, CCI3, CCI4;
double MacdOpenLevel, MacdCloseLevel;
int cnt, ticket, total;
// Initial data checks
// This checks the EA for function on a
// chart and with the supplied external variables
// The test will check only the TakeProfit on a chart of < 100 bars 
   If (Bars<100)
      {
      Print ("bars less than 100");
         return(0);
      }
      If (TakeProfit<10)
      {
      Print ("Take Profit<10");
      return(0); //  check TakeProfit
      }
// To simplify coding and speed up access
// data are put into internal variables
   MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
   SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
   CCI0=iCCI(NULL,0,21,PRICE_TYPICAL,0);
   CCI1=iCCI(NULL,0,21,PRICE_TYPICAL,1);
   CCI2=iCCI(NULL,0,21,PRICE_TYPICAL,2);
   CCI3=iCCI(NULL,0,21,PRICE_TYPICAL,3);
   CCI4=iCCI(NULL,0,21,PRICE_TYPICAL,4);
// Checking the order terminal for any previsouly placed orders
// that didn't execute before proceding,  even though ere shouldn't be
// any since they're all market orders
   total=OrdersTotal();
   if (total<1)  
      // Now we'll check to make sure there's enough money to enter a new trade
      {
      if (AccountFreeMargin()<(1000*Lots))
         {
         Print ("We have no money. Free Margin = " AccountFreeMargin());
         return(0);
         }
         // Next, we'll check for LONG entry opportunities
         if (MacdCurrent<0 && MacdCurrent>SignalCurrent &&
         MacdPrevious<0 && MacdPrevious>SignalPrevious &&
         CCI0>0 && CCI1>0 && CCI1<0 && CCI2<0 && CCI3<0 &&
         CCI4<0 && Ask>PRICE_HIGH,1 &&
         (MathAbs(MacdCurrent>(MacdOpenLevel*Point))))
         {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,
                  "Bills MACD CCI",16384,0,Green);
         if(ticket>0)
            {
            if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print("BUY order opened: ",OrderOpenPrice());
            }
            else Print("Error opening BUY order: ",GetLastError());
            return(0);
            }       
         // Time to check for SHORT opportunities.
         if (MacdCurrent>0 && MacdCurrent<SignalCurrent &&
         MacdPrevious>0 && MacdPrevious<SignalPrevious &&
         CCI0<0 && CCI1<0 && CCI1>0 && CCI2>0 && CCI3>0 &&
         CCI4>0 && (Bid<PRICE_LOW,1) &&
         (MathAbs(MacdCurrent)>(MacdOpenLevel*Point))
         {
         ticket=OrderSend (Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,
                  "Bills MACD CCI",16384,0,Red);
         if(ticket>0)
            {
            if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print("SELL order opened: ",OrderOpenPrice());
            }
            else Print("Error opening SELL order: ",GetLastError());
            return(0);
         }
         // Really not sure about this next part. It pertains to
         // orders previously opened in the cycle, but ???
         //for(cnt=0;cnt<total;cnt++)
         //{
         //OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
         //if (OrderType()<=OP_SELL &&   // Checks for open positions
         //OrderSymbol()==Symbol())   // Checks for Symbol
         //if (OrderType()==OP_BUY)
      // The End
     }
     }

 

Hello Bill,

Use multi-line comments (https://docs.mql4.com/basis/syntax/comments)  to temporarily hide sections of your code from MetaEditor compiler to quickly find your code's issue. Gradually reduce sections of removed code until you receive the error once again. Count your braces as you scan "from top-to bottom" of your code. You'll find it pro.

Also, I write my code one section at a time. Each section is designated a place in the overall program. Give each code block a home and all it's residences will be appeased. You may also wish to label each code block with a single-line comment so you know what house your at. Welcome to the neighborhood, right? Hahaha! ;)


Thank you

 
Thanks for your reply.  Great idea!  I'll give it a try.  I suppose each block should be written so as to be able to compile successfully without being dependent on other parts of the program.  So that would mean, I guess, defining all variables up front and including those definitions whenever compliling a block, right?  Like leaving the definitions visible at all times, and then reavealing only one block of functions at a time to MetaEditor?  That sounds right. Thanks again!
 
BillK:
Thanks for your reply.  Great idea!  I'll give it a try.  I suppose each block should be written so as to be able to compile successfully without being dependent on other parts of the program.  So that would mean, I guess, defining all variables up front and including those definitions whenever compliling a block, right?  Like leaving the definitions visible at all times, and then reavealing only one block of functions at a time to MetaEditor?  That sounds right. Thanks again!

Bill,

Everyone is wearing a smile and clapping hands, right? ;) (clapping hands).

Glad to be of service.


Also,

So that would mean, I guess, defining all variables up front and including those definitions whenever compliling a block, right?

Keep in mind the power of using different scopes. If you declare variables within scopes in your program, variable x located in an internal scope could be a completely different value from its value in an external scope. x could be 7 in an external scope and in an internal scope x could be 3. Yeah, uh-huh ;) Hahaha!


Thank you

 
BillK:

This is my first EA, and I keep getting the  '\end_of_program - unbalanced left parenthesis' error message when compiling, but I can't find any missing parenthesis.  It's based on MACD Sample.  Please help if you can.  Thanks!!!- ----

 <CODE REMOVED>

Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.

 

Or just cont the braces . . .  and use consistent indenting

 //| expert initialization function                                   |
//+------------------------------------------------------------------+

// Defining variables

extern double TakeProfit = 20;
extern double Lots = 1;
extern double Stop = 20;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
int start()
   {
   double MacdCurrent, MacdPrevious, SignalCurrent, SignalPrevious;
   double CCI0, CCI1, CCI2, CCI3, CCI4;
   double MacdOpenLevel, MacdCloseLevel;
   int cnt, ticket, total; 
   // Initial data checks
   // This checks the EA for function on a 
   // chart and with the supplied external variables
   // The test will check only the TakeProfit on a chart of < 100 bars  
   If (Bars<100)
      {
      Print ("bars less than 100");
      return(0);
      }
   If (TakeProfit<10)
      {
      Print ("Take Profit<10");
      return(0); //  check TakeProfit
      }
   // To simplify coding and speed up access
   // data are put into internal variables
   MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
   SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
   CCI0=iCCI(NULL,0,21,PRICE_TYPICAL,0);
   CCI1=iCCI(NULL,0,21,PRICE_TYPICAL,1);
   CCI2=iCCI(NULL,0,21,PRICE_TYPICAL,2);
   CCI3=iCCI(NULL,0,21,PRICE_TYPICAL,3);
   CCI4=iCCI(NULL,0,21,PRICE_TYPICAL,4);
   // Checking the order terminal for any previsouly placed orders
   // that didn't execute before proceding,  even though ere shouldn't be
   // any since they're all market orders 
   total=OrdersTotal();
   if (total<1)   
      // Now we'll check to make sure there's enough money to enter a new trade
      {
      if (AccountFreeMargin()<(1000*Lots))
         {
         Print ("We have no money. Free Margin = " AccountFreeMargin());
         return(0);
         }
      // Next, we'll check for LONG entry opportunities
      if (MacdCurrent<0 && MacdCurrent>SignalCurrent &&
         MacdPrevious<0 && MacdPrevious>SignalPrevious &&
         CCI0>0 && CCI1>0 && CCI1<0 && CCI2<0 && CCI3<0 &&
         CCI4<0 && Ask>PRICE_HIGH,1 && 
         (MathAbs(MacdCurrent>(MacdOpenLevel*Point))))
         {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,
                  "Bills MACD CCI",16384,0,Green);
         if(ticket>0)
            {
            if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print("BUY order opened: ",OrderOpenPrice());
            }
         else Print("Error opening BUY order: ",GetLastError());
         return(0);
         }        
         // Time to check for SHORT opportunities.
         if (MacdCurrent>0 && MacdCurrent<SignalCurrent &&
            MacdPrevious>0 && MacdPrevious<SignalPrevious &&
            CCI0<0 && CCI1<0 && CCI1>0 && CCI2>0 && CCI3>0 &&
            CCI4>0 && (Bid<PRICE_LOW,1) && 
            (MathAbs(MacdCurrent)>(MacdOpenLevel*Point))
            {
            ticket=OrderSend (Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,
                  "Bills MACD CCI",16384,0,Red);
            if(ticket>0)
               {
               if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                  Print("SELL order opened: ",OrderOpenPrice());
               }
            else Print("Error opening SELL order: ",GetLastError());
            return(0);
            }
         // Really not sure about this next part. It pertains to
         // orders previously opened in the cycle, but ???
         //for(cnt=0;cnt<total;cnt++)
         //{
         //OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
         //if (OrderType()<=OP_SELL &&   // Checks for open positions
         //OrderSymbol()==Symbol())   // Checks for Symbol
         //if (OrderType()==OP_BUY)
         // The End
         }
      }
   }      //  <-----  missing brace