Unbalanced Parenthesis and Unexpected End of Program error

 

SO I get this error, I am learning coding, nowhere can I find the CAUSE, I have looked and my parenthesis looks fine but error persists. Followed a tutorial and triple-checked my code.


//+------------------------------------------------------------------+
//|                                                           R2.mq4 |
//|                                                          Quintin |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Quintin"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//--- input parameters
input int               InpMaxTrades      =  1000;             // Max Number of Trades
input double            InpTradeGap       =  300.0;            // Minimum gap between trades
input ENUM_ORDER_TYPE   InpType           =  ORDER_TYPE_BUY;   // Order Type
input double            InpMinProfit      =  1;                // Profit in base currency
input int               InpMagicNumber    =  1;                // Magic number
input string            InpTradeComment   =  __FILE__;         // Trade comment
input double            InpVolume         =  0.1;              // Volume per order

struct STradesum {
   int       count;
   double    profit;
   double    trailPrice; 
};

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
   
   
  }  
void OnTick() {
   
   STradeSum sum {
   GetSum(sum); 
     
   if (sum.profit>InpMinProfit) { // target reached
      CloseAll(); 
   }  else
   if (sum.count==0) { // no trades
      OpenTrade(); 
   }  else 
   if (sum.count<InpMaxTrades) {
      if ( InpType==ORDER_TYPE_BUY 
           && SymbolInfoDouble(Symbol(), SYMBOL_ASK<=sum.trailPrice-InpTradeGap)
           )  { // far enough below
       OpenTrade(); 
   }  else
      if ( InpType==ORDER_TYPE_SELL 
           && SymbolInfoDouble(Symbol(), SYMBOL_BID<=sum.trailPrice+InpTradeGap)
           ) { // far enough above
       OpenTrade();
      }
   }    
 
 }    
 
void  OpenTrade() {

   double   price = (InpType==ORDER_TYPE_BUY)?
                       SymbolInfoDouble(Symbol(), SYMBOL_ASK) :          
                       SymbolInfoDouble(Symbol(), SYMBOL_BID);
   OrderSend(Symbol(), InpType, InpVolume, price, 0, 0 ,0, InpTradeComment, InpMagicNumber);
   
}

void  CloseAll() {

   int   count =  OrdersTotal();
   
   for(int i=count-1;i>=0;i--) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if ( OrderSymbol()==Symbol()
              && OrderMagicNumber()==InpMagicNumber) 
              && OrderType()==InpType
              ) {
            OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0);}   
         }
      }
   }



void  GetSum(STradesum &sum) {

   int   count =  OrdersTotal();
   
   sum.count      = 0;
   sum.profit     = 0.0;
   sum.tradePrice = 0.0;
           
    for (int i = count-1; i>=0; i--) {
       if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
          if ( OrderSymbol()==Symbol()
               && OrderMagicNumber()==InpMagicNumber
               &&OrderType()==InpType
               ) {
             sum.count++;
             sum.profit +=OrderProfit()+OrderSwap()+OrderCommission();
             if (InpType==ORDER_TYPE_BUY) {
                if (sum.trailPrice==0 || OrderOpenPrice()<sum.trailPrice) {
                   sum.trailPrice = OrderOpenPrice();  
                }        
             } else
             if (InpType==ORDER_TYPE_SELL) {
                if (sum.trailPrice==0 || OrderOpenPrice()>sum.trailPrice) {
                   sum.trailPrice = OrderOpenPrice(); 
                }
             }
         }
      }
   }                 
           
   return;
}
//+------------------------------------------------------------------+

'}' - unexpected end of program    R2.mq4    117    1
'{' - unbalanced parentheses    R2.mq4    34    15

 
JSJTradeworx: SO I get this error, I am learning coding, nowhere can I find the CAUSE, I have looked and my parenthesis looks fine but error persists. Followed a tutorial and triple-checked my code.

'}' - unexpected end of program    R2.mq4    117    1
'{' - unbalanced parentheses    R2.mq4    34    15

You have several mistakes in your code but start with the following:

From this ...

STradeSum sum {

To this ...

STradesum sum;

Remember that case is important — "STradeSum" is not the same as "STradesum". So either correct the structure's declaration or change the declaration of the variable of that structure.

After this you will get more errors which you will need to fix. Try to fix them yourself. That is how you learn how to code properly by understanding your own mistakes so that you don't repeat them in the future. If you let others figure it out for you, you will not learn as well.

 
Thanks a lot, it makes sense. Now I can work on the other errors and mistakes, this is how we learn, appreciate the headsup.
 
I have fixed the others that I got, I just missed the S-s not used to focusing on each sylable, comme, dot etc. Will get there though.
 
JSJTradeworx #: Thanks a lot, it makes sense. Now I can work on the other errors and mistakes, this is how we learn, appreciate the headsup.
You are welcome!