Code Error Expert Advisor

 

Hello Comunity,

I need your help I created this short code EA(Expert Advisor) but i can not figure out why is giving me this 2 errors can anybody help? (ERRORS highlighted IN RED)

'{' - unbalanced parentheses IROBOT.mq5 line 64

'}' - unexpected end of program IROBOT.mq5 line 141

Thanks in advance for your expertise :)

// Expert Advisor for trading NAS100 based on technical indicators and money management
// Settings: 5-minute time frame, NY session only

// Indicator variables
double emaBuffer[];
double rsiBuffer[];
double pivotBuffer[];
double tsvBuffer[];

// Indicator handles
int emaHandle;
int rsiHandle;
int pivotHandle;
int tsvHandle;

// Money management variables
double accountBalance = 100000.0;
double riskPercent = 1.0;
double riskRewardRatio = 2.0;
double lotSize;

// Order variables
int orderTicket = 0;
int stopLoss = 0;

// Trading variables
bool isTradeOpen = false;
bool isLongTrade = false;

// Input variables
input string symbolName = "NAS100";
input int pivotLengthLeft = 3;
input int pivotLengthRight = 3;
input int pivotMaxExtension = 10;
input int tsvLength = 13;
input int tsvMaLength = 7;
input int emaLength = 110;
input ENUM_MA_METHOD emaMethod = MODE_SMA;
input int rsiLength = 150;
input ENUM_APPLIED_PRICE rsiSource = PRICE_CLOSE;
input ENUM_MA_METHOD rsiMaMethod = MODE_SMA;
input int rsiMaLength = 35;

// Trading hours
input string tradingStartTime = "13:30:00"; // NY session start time
input string tradingEndTime = "20:00:00"; // NY session end time

void OnInit()
{
    // Set up indicator handles
    emaHandle = iMA(symbolName, PERIOD_M5, emaLength, 0, emaMethod, PRICE_CLOSE);
    rsiHandle = iRSI(symbolName, PERIOD_M5, rsiLength, rsiSource);
    pivotHandle = iCustom(symbolName, PERIOD_M5, "PivotPointsHL Extension", pivotLengthLeft, pivotLengthRight, pivotMaxExtension, 0);
    tsvHandle = iCustom(symbolName, PERIOD_M5, "Time Segmented Volume", tsvLength, tsvMaLength, 0);

    // Calculate lot size based on risk percentage
    accountBalance = 100000.00;
    lotSize = MathFloor(accountBalance * riskPercent / 100.0 / 10000.0) * 10000.0;

    Print("Expert Advisor initialized successfully");
}

void OnTick()
{                              '{' - unbalanced parentheses IROBOT.mq5 line 64
   // Check trading hours
    datetime currentTime = TimeLocal();
    datetime startTime = StrToTime(tradingStartTime);
    datetime endTime = StrToTime(tradingEndTime);

    if (currentTime < startTime || currentTime > endTime)
    {
        return;
    }

    // Calculate stop loss
    double stopLossPrice = 0.0;

    if (isLongTrade)
    {
        double highestWick = 0.0;

        for (int i = 1; i <= 2; i++)
        {
            double candleHigh = High[i];
            double candleLow = Low[i];
            double candleClose = Close[i];

            if (candleHigh > highestWick)
            {
                highestWick = candleHigh;
            }

            if (candleLow > stopLossPrice || stopLossPrice == 0.0)
            {
                stopLossPrice = candleLow;
            }
        }

        stopLossPrice = MathMax(stopLossPrice, highestWick);
    }
    else
    {
        double lowestShadow = 0.0;

        for (int i = 1; i <= 2; i++)
        {
            double candleHigh = High[i];
            double candleLow = Low[i];
            double candleClose = Close[i];

            if (candleLow < lowestShadow || lowestShadow == 0.0)
            {
                lowestShadow = candleLow;
            }

            if (candleHigh < stopLossPrice || stopLossPrice == 0.0)
            {
                stopLossPrice = candleHigh;
            }
        }

        stopLossPrice = MathMin(stopLossPrice, lowestShadow);
    }

    // Check if a trade is open and update stop loss if necessary
    if (isTradeOpen)
    {
        if (stopLossPrice != stopLoss)
        {
            bool result = OrderModify(orderTicket, 0.0, stopLossPrice, 0, 0, clrRed);
            if (!result)
            {
                Print("Error modifying order ", orderTicket, " stop loss to ", stopLossPrice);
            }
            else
            {
                Print("Order ", orderTicket, " stop loss updated to ", stopLossPrice);
                stopLoss = stopLossPrice;
            }
        }
    }  '}' - unexpected end of program IROBOT.mq5 141 5
Money Management by Vince. Implementation as a module for MQL5 Wizard
Money Management by Vince. Implementation as a module for MQL5 Wizard
  • www.mql5.com
The article is based on 'The Mathematics of Money Management' by Ralph Vince. It provides the description of empirical and parametric methods used for finding the optimal size of a trading lot. Also the article features implementation of trading modules for the MQL5 Wizard based on these methods.
 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Forum rules and recommendations - General - MQL5 programming forum (2023)
              Messages Editor

  2. Count your braces and match them.

    void OnTick()
    {                              '{' - unbalanced parentheses IROBOT.mq5 line 64
       ⋮
           // Check if a trade is open and update stop loss if necessary
        if (isTradeOpen)
        {
           ⋮
        }  '}' - unexpected end of program IROBOT.mq5 141 5
    <<<<<<<<< OnTick continues here.
  3. input string tradingStartTime = "13:30:00"; // NY session start time
    input string tradingEndTime = "20:00:00"; // NY session end time
    

    When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.

    See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
    Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
    MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)

    Remember to handle the case where start > end (e.g. 2100 … 0200

 
William Roeder #:
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Forum rules and recommendations - General - MQL5 programming forum (2023)
              Messages Editor

  2. Count your braces and match them.

Hi William,

Thanks for the instructions,

Are you familiar with this types of errors ?

 
David12345671234:

Hello Comunity,

I need your help I created this short code EA(Expert Advisor) but i can not figure out why is giving me this 2 errors can anybody help? (ERRORS highlighted IN RED)

'{' - unbalanced parentheses IROBOT.mq5 line 64

'}' - unexpected end of program IROBOT.mq5 line 141

Thanks in advance for your expertise :)

Was this code generated from ChatGPT?

How will the program know when a trade is open?

You only set it to  bool Tradeopen() = false

 
David12345671234 #: Are you familiar with this types of errors ?

Yes, usually it is result of someone who does not know how to code and expecting ChaGPT to generate code for them (which it does very poorly).

The solution is to learn to code properly yourself (which can take many months or even years) or to hire a human programmer to code it properly.

Reason: