2 errors in EA

harry.jh  

Hi,

Need help in fixing these error pls;

')' - unexpected end of program newpinbar.mq5 59 36

'{' - unbalanced parentheses newpinbar.mq5 14 1

#property copyright "Copyright 2023, Barie"
#property link      "https://barbieea.com"
#property version   "1.00"

input int TakeProfit1=50;
input int TakeProfit2=100;
input int StopLoss=200;
input int TimeStart=9;
input int TimeEnd=17;
input int VolumeMin=100;
input int Risk=5;

int start()
{
    int i;
    int ticket=-1;
    int day=DayOfWeek();
    int hour=Hour();

    if(hour<TimeStart || hour>=TimeEnd || day>=6) return(0);

    for(i=Bars-1; i>=0; i--)
    {
        if(iBars(NULL,0)<=200) break;

        if(Close[i]<Open[i] &&
           Close[i]<Low[i-(int)(BodySize()*0.5)] &&
           Close[i]>(Low[i]+High[i])*0.5 &&
           Open[i]>Close[i+1] &&
           Volume[i]>VolumeMin)
        {
            ticket=OrderSend(Symbol(),OP_SELL,NormalizeDouble(Volume[i],0),Ask,3,
                             Low[i]-StopLoss*Point,High[i]+TakeProfit1*Point,
                             "PinBar Sell",16384,0,Green);

            if(ticket<0) return(0);

            ticket=OrderSend(Symbol(),OP_SELL,NormalizeDouble(Volume[i],0),Ask,3,
                             Low[i]-StopLoss*Point,High[i]+TakeProfit2*Point,
                             "PinBar Sell",16384,0,Green);

            if(ticket<0) return(0);

            return(ticket);
        }
        else if(Close[i]>Open[i] &&
                Close[i]>High[i-(int)(BodySize()*0.5)] &&
                Close[i]<(Low[i]+High[i])*0.5 &&
                Open[i]<Close[i+1] &&
                Volume[i]>VolumeMin)
        {
            ticket=OrderSend(Symbol(),OP_BUY,NormalizeDouble(Volume[i],0),Bid,3,
                             High[i]+StopLoss*Point,Low[i]-TakeProfit1*Point,
                             "PinBar Buy",16384,0,Red);

            if(ticket<0) return(0);

            ticket=OrderSend(Symbol(),OP_BUY,NormalizeDouble(Volume[i],0),Bid,3,
                             High[i]+StopLoss*Point,Low[i]-TakeProfit2*Point,
                             "PinBar Buy",16384,0,Red);

            if(ticket<0) return(0);

            return(ticket);
        }
    }

    return(0);
Lorentzos Roussos  
harry.jh:

Hi,

Need help in fixing these error pls;

')' - unexpected end of program newpinbar.mq5 59 36

'{' - unbalanced parentheses newpinbar.mq5 14 1

Try this : (when you ask chatGPT for a script it literally finds a script and not an expert advisor , also if you did use chatGPT send this code to it as a correction)

It is not tested as i assumed for what you wanted in the trade filtration 

#property copyright "Read the discussion"
#property link      "https://www.mql5.com/en/forum/441063"
#property version   "1.00"
#property strict
input int TakeProfit1=50;
input int TakeProfit2=100;
input int StopLoss=200;
input int TimeStart=9;
input int TimeEnd=17;
input int VolumeMin=100;
input double lotSize=0.01;

datetime barStamp=0;
int OnInit()
  {
  barStamp=0;
  return(INIT_SUCCEEDED);
  }

void OnTick()
  {

    int i;
    int ticket=-1;
    int day=DayOfWeek();
    int hour=Hour();
    //Day of week has Sunday on 0 and Saturday on 6 ! caution on that https://docs.mql4.com/dateandtime/dayofweek

    if(hour<TimeStart || hour>=TimeEnd || day==6 || day==0) return;
    if(Time[0]>barStamp)
    {
    barStamp=Time[0];
    double bodySize=MathAbs(Close[1]-Open[1]);
    if(Close[1]<Open[1] &&
       Close[1]<(Low[2]+bodySize*0.5) &&
       Close[1]>(Low[2]+High[2])*0.5 &&
       Open[1]>Close[2] &&
       Volume[i]>VolumeMin){
            ticket=OrderSend(Symbol(),OP_SELL,lotSize,Bid,1000,
                             High[2]+((double)StopLoss)*_Point,Low[i]-((double)TakeProfit1)*_Point,
                             "PinBar Sell",16384,0,clrGreen);

        }
    else if(Close[1]>Open[1] &&
            Close[1]>(High[2]-bodySize*0.5) &&
            Close[1]<(Low[2]+High[2])*0.5 &&
            Open[1]<Close[2] &&
            Volume[i]>VolumeMin)
        {
            ticket=OrderSend(Symbol(),OP_BUY,lotSize,Ask,1000,
                             Low[2]-((double)StopLoss)*_Point,High[2]+((double)TakeProfit1)*_Point,
                             "PinBar Buy",16384,0,clrRed);
        }
   }  
  }


Lorentzos Roussos  
VikMorroHun #:

I'm not sure what does ChatGPT have to do with this.  All you need to do is add a

symbol at the end of your code to fix the unbalanced parentheses/unexpected end of program error messages.

That's all he has to do huh ? 

William Roeder  
  1.            ticket=OrderSend(Symbol(),OP_SELL,lotSize,Bid,1000,
                                 High[2]+((double)StopLoss)*_Point,Low[i]-((double)TakeProfit1)*_Point,
                                 "PinBar Sell",16384,0,clrGreen);

    Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2.             return(ticket);
            }
        } // end of for
    
        return(0);
     // where is the end of start?

    MT4: Learn to code it.
    MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

  3. int start()
    {

    You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

Reason: