"Unexpected end of program" and "Unbalanced parentheses" Expert Advisor Problem! - page 4

 
Ricksters #:

Code Error generated by the coded copied into MQL4 editor are as follows..;' - unexpected end of program & unbalanced parentheses  - Kindly see assist in fixing this errors - See detail source code below:

<Incorrectly posted code deleted>

Please read the topic. Your problem has probably already been addressed.

See Fernando's post just a few above yours?

https://www.mql5.com/en/forum/291541/page3#comment_44043800

If you had read his post, you would know how to post code correctly!

"Unexpected end of program" and "Unbalanced parentheses" Expert Advisor Problem!
"Unexpected end of program" and "Unbalanced parentheses" Expert Advisor Problem!
  • 2022.04.30
  • www.mql5.com
Hello! So, I have Expert Advisor that doesn't work and gives me those two errors: "Unexpected end of program" and "Unbalanced Parentheses...
 

Code was generated by ChatGPT

//+------------------------------------------------------------------+
//| Multi-Indicator EA Template.mq4 |
//| |
//+------------------------------------------------------------------+

#include <Trade\Trade.mqh>
#include <Indicators\MovingAverage.mqh>
#include <Indicators\RSI.mqh>
#include <Indicators\MACD.mqh>
#include <Indicators\ADX.mqh>
#include <Indicators\Stochastic.mqh>
#include <Indicators\Bands.mqh>

// EA properties

// Time Frame
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1;

// Moving Average
input bool Use_Fast_MA = true;
input int Fast_MA_Period = 9;
input ENUM_APPLIED_PRICE Fast_MA_Price = PRICE_CLOSE;
input ENUM_MA_METHOD Fast_MA_Method = MODE_EMA;
input bool Use_Slow_MA = true;
input int Slow_MA_Period = 21;
input ENUM_APPLIED_PRICE Slow_MA_Price = PRICE_CLOSE;
input ENUM_MA_METHOD Slow_MA_Method = MODE_EMA;

// RSI
input bool Use_RSI = true;
input int RSI_Period = 14;
input ENUM_APPLIED_PRICE RSI_Price = PRICE_CLOSE;
input double RSI_Overbought = 70;
input double RSI_Oversold = 30;

// MACD
input bool Use_MACD = true;
input int MACD_Fast_Period = 12;
input int MACD_Slow_Period = 26;
input int MACD_Signal_Period = 9;

// ADX
input bool Use_ADX = true;
input int ADX_Period = 14;
input double ADX_Level = 25;

// Stochastic Oscillator
input bool Use_Stoch = true;
input int Stoch_K_Period = 14;
input int Stoch_D_Period = 3;
input int Stoch_Slowing = 3;
input ENUM_MA_METHOD Stoch_Method = MODE_SMA;
input ENUM_STO_PRICE Stoch_Price = STO_LOWHIGH;

// Bollinger Bands
input bool Use_BB = true;
input int BB_Period = 20;
input double BB_Deviation = 2;
input ENUM_MA_METHOD BB_Method = MODE_SMA;
input ENUM_APPLIED_PRICE BB_Price = PRICE_CLOSE;

// Trade settings
input double StopLoss_Points = 100;
input double TakeProfit_Points = 200;
input double LotSize = 0.01;

// Global variables
CTrade trade;
CMovingAverage Fast_MA, Slow_MA;
CRSI RSI;
CMACD MACD;
CADX ADX;
CStochastic Stoch;
CBands BB;

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if (Use_Fast_MA) Fast_MA.Create(_Symbol, TimeFrame, Fast_MA_Period, Fast_MA_Method, Fast_MA_Price);
if (Use_Slow_MA) Slow_MA.Create(_Symbol, TimeFrame, Slow_MA_Period, Slow_MA_Method, Slow_MA_Price);
if (Use_RSI) RSI.Create(_Symbol, TimeFrame, RSI_Period, RSI_Price);
if (Use_MACD) MACD.Create(_Symbol, TimeFrame, MACD_Fast_Period, MACD_Slow_Period, MACD_Signal_Period);
if (Use_ADX) ADX.Create(_Symbol, TimeFrame, ADX_Period);
if (Use_Stoch) Stoch.Create(_Symbol, TimeFrame, Stoch_K_Period, Stoch_D_Period,

',' - unexpected end of program 72 83

'{' - unbalanced parentheses 66 1

can anyone tell me where is the error??

 
Almotasim Billah Ahmed Sobhy Mohamed #:
User has confessed in privte that the code was generated by ChatGPT.

',' - unexpected end of program 72 83

'{' - unbalanced parentheses 66 1

can anyone tell me where is the error??

  • Usually people who cannot code do not receive free help on this forum, although it could happen if you are lucky. Be patient.
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community.
  • If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free).
  • Finally, you also have the option to hire a programmer in the Freelance section.
  •  
    Almotasim Billah Ahmed Sobhy Mohamed #:

    Code was generated by ChatGPT

    can anyone tell me where is the error??

    Stop using ChatGPT.
              Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum (2023)

     

    ...

    Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

    Code button in editor

    Hover your mouse over your post and select "edit" ... 

    ...

    PLEASE  i need help on unexpected end of programm and (for) expression are not allowed on a global scope. please how do i fixed this error

     
    @Wojujutari Kenni #: PLEASE  i need help on unexpected end of programm and (for) expression are not allowed on a global scope. please how do i fixed this error

    If your code was generated by ChatGPT, then we cannot help you! Learn to code or hire someone human to code it for you.

     

    Hi every one,

    I am neew to coding and I decided to convert an indicator to a mqh file. I did about 98 percent but the error of '}' - unexpected end of program MySignal.mqh 302 3     was created.

    Although, I try so many times to balance it and so on ... but the error is not fixed.

    please help me out to sole this issue .

    thanks in

    Hi every one,
    
    I am new to coding and I decided to convert an indicator to a mqh file. I did about 98 percent but the error of '}' - unexpected end of program MySignal.mqh    302     3     was created.
    
    Although, I try so many times to balance it and so on ... but the error is not fixed.
    
    Please help me to solve this issue.
    
    thanks, in advance.
    //+------------------------------------------------------------------+
    //|                                                     MySignal.mqh |
    //|                                  Copyright 2023, MetaQuotes Ltd. |
    //|                                             https://www.mql5.com |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2023, MetaQuotes Ltd."
    #property link      "https://www.mql5.com"
    #include <Expert\ExpertSignal.mqh>
    // wizard description start
    //+------------------------------------------------------------------+
    //| Description of the class                                         |
    //| Title=Signal of the 'Custom Indicator' Detrended Price Oscillator|                 
    //| Type=SignalAdvanced                                              |
    //| Name=DetrendedPriceOscillator                                    |
    //| ShortName=DPO                                                    |
    //| Class=CSignalDetrendedPriceOscillator                            |
    //| Page=signal_ma                                                   |
    //| Parameter=PeriodMA,int,14,Period of averaging                    |
    //| Parameter=Shift,int,0,Time shift                                 |
    //| Parameter=Method,ENUM_MA_METHOD,MODE_EMA,Method of averaging     |
    //| Parameter=Applied,ENUM_APPLIED_PRICE,PRICE_CLOSE,Prices series   |
    //| Parameter=Barstocount,int,400,Number of Bars to count            |
    //| Parameter=TriggerCandle,int,Current,Previous,Candle to entry     |
    
    //+------------------------------------------------------------------+
    // wizard description end
    //+------------------------------------------------------------------+
    //| Class CSignalDetrended Price Oscillator.                         |
    //| Purpose: Class of generator of trade signals based on            |
    //|          the 'Detrended Price Oscillator' indicator.             |
    //| Is derived from the CExpertSignal class.                         |
    //+------------------------------------------------------------------+
    class CSignalMyCustInd  : public CExpertSignal
      {
    protected: 
       CiCustom            m_mci;                                                         // indicator object "MyCustomIndicator"
       //--- adjusted parameters
       int                 m_ma_period;                            // the "period of averaging" parameter of the indicator
       int                 m_ma_shift;                              // the "time shift" parameter of the indicator
       int                 m_DetrendedPriceOscillator_Barstocount;                        // the "Bars to count" parameter of the indicator 
       int                m_DetrendedPriceOscillator_TriggerCandle;                       // the "TriggerCandle" parameter of the indicator
       ENUM_MA_METHOD      m_ma_method;                             // the "method of averaging" parameter of the indicator
       ENUM_APPLIED_PRICE  m_ma_applied;                            // the "object of averaging" parameter of the indicator
       //--- "weights" of market models (0-100)
       int               m_pattern_0;      // model 0 "price is on the necessary side from the indicator"
       int               m_pattern_1;      // model 1 "price crossed the indicator with opposite direction"
       int               m_pattern_2;      // model 2 "price crossed the indicator with the same direction"
       int               m_pattern_3;      // model 3 "piercing"
    
    
    public:
                         CSignalMyCustInd(void);
                        ~CSignalMyCustInd(void);
       //--- methods of setting adjustable parameters
       void              PeriodMA(int value)               { m_ma_period=value;           }
             
       void              Shift(int value)                    { m_ma_shift=value;       }
        void              Method(ENUM_MA_METHOD value)        { m_ma_method=value;          }
       void              Applied(ENUM_APPLIED_PRICE value)   { m_ma_applied=value;               }
       //--- methods of adjusting "weights" of market models
       void              Pattern_0(int value)                { m_pattern_0=value;          }
       void              Pattern_1(int value)                { m_pattern_1=value;          }
       void              Pattern_2(int value)                { m_pattern_2=value;          }
       void              Pattern_3(int value)                { m_pattern_3=value;          }
       //--- method of verification of settings
       virtual bool      ValidationSettings(void);
       //--- method of creating the indicator and time series
       virtual bool      InitIndicators(CIndicators *indicators);
       //--- methods of checking if the market models are generated
       virtual int       LongCondition(void);
       virtual int       ShortCondition(void);
    
    protected:
       //--- indicator initialization method
       bool              InitMyCustomIndicator(CIndicators *indicators);
       //--- methods of getting data
       //- getting the indicator value
       double            Main(int ind) { return(m_mci.GetData(0,ind));      }
       //- getting the signal line value
       double            Signal(int ind) { return(m_mci.GetData(1,ind));    }
       //- difference between two successive indicator values
       double            DiffMain(int ind) { return(Main(ind)-Main(ind+1)); }
       int               StateMain(int ind);
       double            State(int ind) { return(Main(ind)-Signal(ind)); }
       //- preparing data for the search
       bool              ExtState(int ind);
       //- searching the market model with the specified parameters
       bool              CompareMaps(int map,int count,bool minimax=false,int start=0);
      };
    //+------------------------------------------------------------------+
    //| Constructor                                                      |
    //+------------------------------------------------------------------+
    CSignalMyCustInd::CSignalMyCustInd(void) : m_ma_period(12),
                                               
                                               m_ma_method(MODE_SMA),
                                               m_ma_applied(PRICE_CLOSE),
                                               m_pattern_0(0),
                                               m_pattern_1(0)
      {
    //--- initialization of protected data
       m_used_series=USE_SERIES_OPEN+USE_SERIES_HIGH+USE_SERIES_LOW+USE_SERIES_CLOSE;
      }
    //+------------------------------------------------------------------+
    //| Destructor                                                       |
    //+------------------------------------------------------------------+
    CSignalMyCustInd::~CSignalMyCustInd(void)
      {
      }
    //+------------------------------------------------------------------+
    //| Checking parameters of protected data                              |
    //+------------------------------------------------------------------+
    bool CSignalMyCustInd::ValidationSettings(void)
      {
    //--- validation settings of additional filters
       if(!CExpertSignal::ValidationSettings())
          return(false);
    //--- initial data checks
        if(m_ma_period<=0)
         {
          printf(__FUNCTION__+": period must be greater than moving average value");
          return(false);
         }
    //--- ok
       return(true);
      }
    //+------------------------------------------------------------------+
    //| Create indicators.                                               |
    //+------------------------------------------------------------------+
    bool CSignalMyCustInd::InitIndicators(CIndicators *indicators)
      {
    //--- check of pointer is performed in the method of the parent class
    //---
    //--- initialization of indicators and time series of additional filters
       if(!CExpertSignal::InitIndicators(indicators))
          return(false);
    //--- creation and initialization of the custom indicator
       if(!InitMyCustomIndicator(indicators))
          return(false);
    //--- ok
       return(true);
      }
    //+------------------------------------------------------------------+
    //| Initialization of indicators.                                    |
    //+------------------------------------------------------------------+
    bool CSignalMyCustInd::InitMyCustomIndicator(CIndicators *indicators)
       {
    //--- add an object to the collection
       if(!indicators.Add(GetPointer(m_mci)))
        {
          printf(__FUNCTION__+": error adding object");
          return(false);
          }
    //--- initialization of indicators and timeseries of additional filters
       if(!CExpertSignal::InitIndicators(indicators))
       {
          return(false); 
          }  
     //--- create and initialize CSignalMyCustInd
       if(!InitMA(indicators))
       
          return(false);    
    //--- set parameters of the indicator
    
       MqlParam parameters[4];
       
    //---
    {
       parameters[0].type=TYPE_STRING;
       parameters[0].string_value="Include\\Detrended Price Oscillator.ex5";
       parameters[1].type=TYPE_INT;
       parameters[1].integer_value=m_ma_period;
      }
    //--- object initialization
    if(!m_ma.Create(m_symbol.Name(),m_period,m_ma_period,m_ma_shift,m_ma_method,m_ma_applied))
      {
         printf(__FUNCTION__+": error initializing object");
          return(false);
         }
    //--- check pointer
       if(!m_mci.Create(m_symbol.Name(),0,IND_CUSTOM,4,parameters))
         {
          printf(__FUNCTION__+": error initializing object");
          return(false);
         }
         //--- add object to collection
       if(!indicators.Add(GetPointer(m_ma)))
       return(false);
       {
    //--- number of buffers
       if(!m_mci.NumBuffers(4)) return(false);
    //--- ok
       return(true);
      }
      
    //+------------------------------------------------------------------+
    //| "Voting" that the price will grow.                               |
    //+------------------------------------------------------------------+
    int CSignalMyCustInd::LongCondition(void)
      {
       int result=0;
       int idx   =StartIndex();
    //--- analyze positional relationship of the close price and the indicator at the first analyzed bar
       if(DiffCloseMA(idx)<0.0)
         {
          //--- the close price is below the indicator
          if(IS_PATTERN_USAGE(1) && DiffOpenMA(idx)>0.0 && DiffMA(idx)>0.0)
            {
             //--- the open price is above the indicator (i.e. there was an intersection), but the indicator is directed upwards
             result=m_pattern_1;
             //--- consider that this is an unformed "piercing" and suggest to enter the market at the current price
             m_base_price=0.0;
            }
         }
       else
         {
          //--- the close price is above the indicator (the indicator has no objections to buying)
          if(IS_PATTERN_USAGE(0))
             result=m_pattern_0;
          //--- if the indicator is directed upwards
          if(DiffMA(idx)>0.0)
            {
             if(DiffOpenMA(idx)<0.0)
               {
                //--- if the model 2 is used
                if(IS_PATTERN_USAGE(2))
                  {
                   //--- the open price is below the indicator (i.e. there was an intersection)
                   result=m_pattern_2;
                   //--- suggest to enter the market at the "roll back"
                   m_base_price=m_symbol.NormalizePrice(MA(idx));
                  }
               }
             else
               {
                //--- if the model 3 is used and the open price is above the indicator
                if(IS_PATTERN_USAGE(3) && DiffLowMA(idx)<0.0)
                  {
                   //--- the low price is below the indicator
                   result=m_pattern_3;
                   //--- consider that this is a formed "piercing" and suggest to enter the market at the current price
                   m_base_price=0.0;
                  }
               }
            }
         }
    //--- return the result
       return(result);
      }
    //+------------------------------------------------------------------+
    //| "Voting" that price will fall.                                   |
    //+------------------------------------------------------------------+
    int CSignalMyCustInd::LongCondition(void)
      {
       int result=0;
       int idx   =StartIndex();
    //--- analyze positional relationship of the close price and the indicator at the first analyzed bar
       if(DiffCloseMA(idx)>0.0)
         {
          //--- the close price is above the indicator
          if(IS_PATTERN_USAGE(1) && DiffOpenMA(idx)<0.0 && DiffMA(idx)<0.0)
            {
             //--- the open price is below the indicator (i.e. there was an intersection), but the indicator is directed downwards
             result=m_pattern_1;
             //--- consider that this is an unformed "piercing" and suggest to enter the market at the current price
             m_base_price=0.0;
            }
         }
       else
         {
          //--- the close price is below the indicator (the indicator has no objections to buying)
          if(IS_PATTERN_USAGE(0))
             result=m_pattern_0;
          //--- the indicator is directed downwards
          if(DiffMA(idx)<0.0)
            {
             if(DiffOpenMA(idx)>0.0)
               {
                //--- if the model 2 is used
                if(IS_PATTERN_USAGE(2))
                  {
                   //--- the open price is above the indicator (i.e. there was an intersection)
                   result=m_pattern_2;
                   //--- suggest to enter the market at the "roll back"
                   m_base_price=m_symbol.NormalizePrice(MA(idx));
                  }
               }
             else
               {
                //--- if the model 3 is used and the open price is below the indicator
                if(IS_PATTERN_USAGE(3) && DiffHighMA(idx)>0.0)
                  {
                   //--- the high price is above the indicator
                   result=m_pattern_3;
                   //--- consider that this is a formed "piercing" and suggest to enter the market at the current price
                   m_base_price=0.0;
                  }
               }
            }
         }
    //--- return the result
       return(result);
      }
    //+------------------------------------------------------------------+
    
    


    Files:
    MySignal.mqh  14 kb
     
    Ali Mirzabagherian #: I am neew to coding and I decided to convert an indicator to a mqh file.

    That is nonsense. You still have to include it into MQL4 file, so you still have an indicator. Right back where you started.

     
    William Roeder #:

    That is nonsense. You still have to include it into MQL4 file, so you still have an indicator. Right back where you started.


    thanks for your response, sir. You know, I want to add the DPO oscillator to my EA. So, I have to convert the ex5 (mql) to mqh(custom indi). 

    please guide me in more detail, if it is possible.

    thanks

     
    Ali Mirzabagherian #: thanks for your response, sir. You know, I want to add the DPO oscillator to my EA. So, I have to convert the ex5 (mql) to mqh(custom indi).  please guide me in more detail, if it is possible.

    Why are you going to so much trouble? Just use the indicator via the iCustom() call, and if you want to embed the indicator inside the final ".ex5" file, then just declare it as a resource.

    Reason: