Unbalanced parenthesis error

 

been working on this inside bar expert advisor and i had issues with it giving continuos non stop alerts but tried to solve it but now it wont compile because of a unbalanced parenthesis on the  "void OnTick(){" line 23 in the code below. can you guys please help me balance the parenthesis as i have been at it for hours without winning. thanks in advance.

//+------------------------------------------------------------------+
//|                               Consolidation Candles Detector.mq5 |
//|                                       Copyright 2023, ELDigital. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Trade/Trade.mqh>
#resource "\\Files\\email.wav"
#resource "\\Files\\ok.wav"
 
input ENUM_TIMEFRAMES Timeframe= PERIOD_CURRENT; 

int totalBars;
 
 int OnInit(){
   PlaySound("::Files\\ok.wav");
   totalBars = iBars(_Symbol,Timeframe);
   return(INIT_SUCCEEDED);
 }

 void OnDeinit(const int reason){ 
 }

 void OnTick(){
 int bars = iBars(_Symbol,Timeframe);
 if(totalBars != bars){
     totalBars = bars;
 getConsolidationSignal(); 
 } 
    int getConsolidationSignal(){
    datetime time = iTime(_Symbol,PERIOD_CURRENT,1);
    
    double high1 = iHigh(_Symbol,PERIOD_CURRENT,1);
    double low1 = iLow(_Symbol,PERIOD_CURRENT,1);
    double open1 = iOpen(_Symbol,PERIOD_CURRENT,1);
    double close1 = iClose(_Symbol,PERIOD_CURRENT,1);
    
    double high2 = iHigh(_Symbol,PERIOD_CURRENT,2);
    double low2 = iLow(_Symbol,PERIOD_CURRENT,2);
    double open2 = iOpen(_Symbol,PERIOD_CURRENT,2);
    double close2 = iClose(_Symbol,PERIOD_CURRENT,2);
  
   //Consolidation formation
   if(close1 < high2){
      if(close1 > low2){
         createObj(time,low1,217);
         Print(_FUNCTION_," >Consolidation Signal...");
         Alert("Consolidation Alert");
         PlaySound("::Files\\email.wav");
    // Send a push notification
   string symbolName = Symbol();  
   string message = symbolName + " - Consolidation Signal Alert";
   int pushNotificationResult = SendNotification(message);

   if (pushNotificationResult)
 {
    Print("Push notification sent successfully.");
 }
 else
 {
    Print("Failed to send push notification.");
 }                                                
             return 1;
                }
             }
   return 0; 
 }
 void createObj(datetime time, double price, int arrowCode){
     string objName = "";
     StringConcatenate(objName, "Signal@",time,"at",DoubleToString(price,_Digits),"(",arrowCode,")");
     if(ObjectCreate(0,objName,OBJ_ARROW,0,time,price)){
        ObjectSetInteger(0,objName, OBJPROP_ARROWCODE,arrowCode);   
     }     
 }
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.11.01
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Please use the MetaEditor Styler to properly format your code and align your brackets. That will allow you to quickly see where the problem may be.
Styler - Developing programs - MetaEditor Help
  • www.metatrader5.com
The styler quickly brings a source code design in line with the recommended standard. This makes the code look professional and easy to read. A...
 
Fernando Carreiro #:
Please use the MetaEditor Styler to properly format your code and align your brackets. That will allow you to quickly see where the problem may be.

thanks for the tip but Im still not winning.

 
ELDIGITAL #: thanks for the tip but Im still not winning.
Show you "new" code with the proper styling!
 
Fernando Carreiro #:
here is the new proper styled code, how do i balance the parenthis in line 23? im not well versed with programming please look at it and fix it for me
//+------------------------------------------------------------------+
//|                               Consolidation Candles Detector.mq5 |
//|                                       Copyright 2023, ELDigital. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Trade/Trade.mqh>
#resource "\\Files\\email.wav"
#resource "\\Files\\ok.wav"

input ENUM_TIMEFRAMES Timeframe= PERIOD_CURRENT;

int totalBars;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   PlaySound("::Files\\ok.wav");
   totalBars = iBars(_Symbol,Timeframe);
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   int bars = iBars(_Symbol,Timeframe);
   if(totalBars != bars)
     {
      totalBars = bars;
      getConsolidationSignal();
     }
   int getConsolidationSignal()
     {
      datetime time = iTime(_Symbol,PERIOD_CURRENT,1);

      double high1 = iHigh(_Symbol,PERIOD_CURRENT,1);
      double low1 = iLow(_Symbol,PERIOD_CURRENT,1);
      double open1 = iOpen(_Symbol,PERIOD_CURRENT,1);
      double close1 = iClose(_Symbol,PERIOD_CURRENT,1);

      double high2 = iHigh(_Symbol,PERIOD_CURRENT,2);
      double low2 = iLow(_Symbol,PERIOD_CURRENT,2);
      double open2 = iOpen(_Symbol,PERIOD_CURRENT,2);
      double close2 = iClose(_Symbol,PERIOD_CURRENT,2);

      //Consolidation formation
      if(close1 < high2)
        {
         if(close1 > low2)
           {
            createObj(time,low1,217);
            Print(_FUNCTION_," >Consolidation Signal...");
            Alert("Consolidation Alert");
            PlaySound("::Files\\email.wav");
            // Send a push notification
            string symbolName = Symbol();
            string message = symbolName + " - Consolidation Signal Alert";
            int pushNotificationResult = SendNotification(message);

            if(pushNotificationResult)
              {
               Print("Push notification sent successfully.");
              }
            else
              {
               Print("Failed to send push notification.");
              }
            return 1;
           }
        }
      return 0;
     }
   void createObj(datetime time, double price, int arrowCode)
     {
      string objName = "";
      StringConcatenate(objName, "Signal@",time,"at",DoubleToString(price,_Digits),"(",arrowCode,")");
      if(ObjectCreate(0,objName,OBJ_ARROW,0,time,price))
        {
         ObjectSetInteger(0,objName, OBJPROP_ARROWCODE,arrowCode);
        }
     }
//+------------------------------------------------------------------+
 

Did you not see this in your code?

void OnTick()
  {
   int bars = iBars(_Symbol,Timeframe);
   if(totalBars != bars)
     {
      totalBars = bars;
      getConsolidationSignal();
     }
   int getConsolidationSignal()
     {
      datetime time = iTime(_Symbol,PERIOD_CURRENT,1);

You are declaring a new function before closing off the OnTick() function.

void OnTick()
  {
   int bars = iBars(_Symbol,Timeframe);
   if(totalBars != bars)
     {
      totalBars = bars;
      getConsolidationSignal();
     }
  }

int getConsolidationSignal()
  {
   datetime time = iTime(_Symbol,PERIOD_CURRENT,1);

...
There may be other errors. I only looked at this one.
 
Fernando Carreiro #:

Did you not see this in your code?

You are declaring a new function before closing off the OnTick() function.

There may be other errors. I only looked at this one.

thank you so much, it sucessfully compiled.

 

  i have been working on this inside bar expert advisor and i had issues with it giving continuos non stop alerts but tried to solve it but now it wont compile because of a unbalanced parenthesis on the  "void OnTick(){" line 13 in the code below. can you guys please help me balance the parenthesis as i have been at it for hours without winning. thanks in advance.


//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   ""
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
void OnTick()
  {
// Input parameters
   input int EMAPeriod50 = 50;
   input int EMAPeriod100 = 100;
   input int EMAPeriod150 = 150;
   input int EMAPeriod200 = 200;
   input double LotSize = 0.01;
   input int CrossingCandleQty = 1;
   input double StopLoss = 100; // Default stop loss
   input double TakeProfit = 100; // Default take profit

// indicator handles
   int ema_handle_50, ema_handle_100, ema_handle_150, ema_handle_200;

// create an empty string for the signal;
   string signal="";

// create an Array for several prices
   double myMovingAverageArray1[],myMovingAvrageArray2[],myMovingAverageArray3[],myMovingAverageArray4[];

// define the properties of the Moving Average1
   int movingAverageDefinition1 = iMA(_Symbol,_Period,50,0,MODE_EMA,PRICE_CLOSE);

// define the properties of the Moving Average2
   int movingAverageDefinition2 = iMA(_Symbol,_Period,100,0,MODE_EMA,PRICE_CLOSE);

// define the properties of the Moving Average3
   int movingAverageDefinition3 = iMA(_Symbol,_Period,150,0,MODE_EMA,PRICE_CLOSE);

// define the properties of the Moving Average4
   int movingAverageDefinition4 = iMA(_Symbol,_Period,200,0,MODE_EMA,PRICE_CLOSE);

// sort the price array1 from the current candle downwards
   ArraySetAsSeries(myMovingAverageArray1,true);

// sort the price array2 from the current candle downwards
   ArraySetAsSeries(myMovingAverageArray2,true);

// sort the price array3 from the current candle downwards
   ArraySetAsSeries(myMovingAverageArray3,true);

// sort the price array4 from the current candle downwards
   ArraySetAsSeries(myMovingAverageArray4,true);

// Defined MA1, one line,current candle,3 candles, store result
   CopyBuffer(movingAverageDefinition1,0,0,3,myMovingAverageArray1);

// Defined MA2, one line,current candle,3 candles, store result
   CopyBuffer(movingAverageDefinition2,0,0,3,myMovingAverageArray2);

// Defined MA3, one line,current candle,3 candles, store result
   CopyBuffer(movingAverageDefinition3,0,0,3,myMovingAverageArray3);

// Defined MA4, one line,current candle,3 candles, store result
   CopyBuffer(movingAverageDefinition4,0,0,3,myMovingAverageArray4);

// calculate MA1 for the current candle
   double myMovingAverageValue1=myMovingAverageArray1[0];

// calculate MA2 for the current candle
   double myMovingAverageValue2=myMovingAverageArray2[0];

// calculate MA3 for the current candle
   double myMovingAverageValue3=myMovingAverageArray3[0];

// calculate MA4 for the current candle
   double myMovingAverageValue4=myMovingAverageArray4[0];

// Sell Signal
   if(myMovingAverageValue1 < myMovingAverageValue2)
      if(myMovingAverageValue2 < myMovingAverageValue3)
         if(myMovingAverageValue3 < myMovingAverageValue4)
           {
            sigmal="SELL";
           }

// Buy Signal
   if(myMovingAverageValue1 > myMovingAverageValue2)
      if(myMovingAverageValue2 > myMovingAverageValue3)
         if(myMovingAverageValue3 > myMovingAverageValue4)
           {
            signal="BUY";
           }
   Comment {"Signal: ",signal,"\n"
            "myMovingAverageValue1: ",myMovingAverageValue1,"\n",
            "myMovingAverageValue2: ",myMovingAverageValue2,"\n",
            "myMovingAverageValue3: ",myMovingAverageValue3,"\n",
            "myMovingAverageValue4: ",myMovingAverageValue4,"\n",
           );

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



   

 
Varush #:

  i have been working on this inside bar expert advisor and i had issues with it giving continuos non stop alerts but tried to solve it but now it wont compile because of a unbalanced parenthesis on the  "void OnTick(){" line 13 in the code below. can you guys please help me balance the parenthesis as i have been at it for hours without winning. thanks in advance.




   

create a new post, this is an old post you replied to. Go to forum, and post your issue

Reason: