Hi Guys. I am having 2 error codes on my code i am unable to fix.

 
I need help fixing this error in my code: "Unexpected end of program' and 'unbalanced Parentheses". When i try to fix it i get more errors. Here is the code:
void OnTick()
{
    // Check for open orders
    if (OrdersTotal() > 0)
    {
        return; // If there are open orders, do nothing
    }
    
    // Calculate the indicators
    double macd_current = iMACD(_Symbol, _Period, _FastEMA, _SlowEMA, _SignalMA, PRICE_CLOSE, MODE_MAIN, 0);
    double ma1_current = iMA(_Symbol, _Period, _MA1_Period, 0, MODE_SMA, PRICE_CLOSE, 0);
    double ma2_current = iMA(_Symbol, _Period, _MA2_Period, 0, MODE_SMA, PRICE_CLOSE, 0);
    
    // Check for buy signal
    if (macd_current > 0 && macd_last < 0 && ma1_current > ma2_current)
    {
        double lot_size = _LotSize;
        if (_UseMartingale)
        {
            int magic_number = int(_MagicNumber);
            int attempts = 0;
            double loss = 0.0;
            while (attempts < _MaxMartingaleAttempts)
            {
                // Place the buy order with the current lot size
                double stop_loss = NormalizeDouble(Bid - _StopLoss * _Point, _Digits);
                double take_profit = NormalizeDouble(Bid + _TakeProfit * _Point, _Digits);
                int ticket = OrderSend(_Symbol, OP_BUY, lot_size, Ask, _Slippage, stop_loss, take_profit, "Buy Order", magic_number);
                
                if (ticket > 0)
                {
                    // Order placed successfully
                    break;
                }
                else
                {
                    // Order failed, increase the lot size
                    lot_size *= _MartingaleMultiplier;
                    attempts++;
                    loss = -1 * _StopLoss * lot_size * _Point;
                    if (attempts >= _MaxMartingaleAttempts)
                    {
                        Print("Max martingale attempts reached, no order placed");
                    }
                    else
                    {
                        Print("Order failed, increasing lot size to " + DoubleToString(lot_size, 2));
                    }
                }
            }
            if (attempts > 0)
            {
                double balance = AccountBalance();
                Print("Martingale loss of " + DoubleToString(loss, 2) + " on account balance of " + DoubleToString(balance, 2));
            }
        }
        else
        {
            // Place the buy order with the specified lot size
            double stop_loss = NormalizeDouble(Bid - _StopLoss * _Point, _Digits);
            double take_profit = NormalizeDouble(Bid + _TakeProfit * _Point, _Digits);
            int ticket = OrderSend(_Symbol, OP_BUY, lot_size, Ask, _Slippage, stop_loss, take_profit, "Buy Order", _MagicNumber);
            if (ticket > 0)
            {
                Print("Buy order placed successfully");
            }
            else
            {
                Print("Buy order failed with error code " + GetLastError());
            }
        }
    }
    
    // Check for sell signal
    if (macd_current < 0 && macd_last > 0 && ma1_current < ma2_current)
        {
        double lot_size = _LotSize;
        if (_UseMartingale)
        {
            int magic_number = int(_MagicNumber);
            int attempts = 0;
            double loss = 0.0;
            while (attempts < _MaxMartingaleAttempts)
            {
                // Place the buy order with the current lot size
                double stop_loss = NormalizeDouble(Bid - _StopLoss * _Point, _Digits);
                double take_profit = NormalizeDouble(Bid + _TakeProfit * _Point, _Digits);
                int ticket = OrderSend(_Symbol, OP_SELL, lot_size, Ask, _Slippage, stop_loss, take_profit, "Sell Order", magic_number);
                
                if (ticket > 0)
                {
                    // Order placed successfully
                    break;
                }
                else
                {
                    // Order failed, increase the lot size
                    lot_size *= _MartingaleMultiplier;
                    attempts++;
                    loss = -1 * _StopLoss * lot_size * _Point;
                    if (attempts >= _MaxMartingaleAttempts)
                    {
                        Print("Max martingale attempts reached, no order placed");
                    }
                    else
                    {
                        Print("Order failed, increasing lot size to " + DoubleToString(lot_size, 2));
                    }
                }
            }
            if (attempts > 0)
            {
                double balance = AccountBalance();
                Print("Martingale loss of " + DoubleToString(loss, 2) + " on account balance of " + DoubleToString(balance, 2));
            }
        }
        else
        {
            // Place the buy order with the specified lot size
            double stop_loss = NormalizeDouble(Bid - _StopLoss * _Point, _Digits);
            double take_profit = NormalizeDouble(Bid + _TakeProfit * _Point, _Digits);
            int ticket = OrderSend(_Symbol, OP_SELL, lot_size, Ask, _Slippage, stop_loss, take_profit, "Sell Order", _MagicNumber);
            if (ticket > 0)
            {
                Print("Sell order placed successfully");
            }
            else
            {
                Print("Sell order failed with error code " + GetLastError());
            }
        }
    }
 

Even if you fix the parenthesis problem, it will not work because this is a part of some EA. 

Where did you get this? You should go there and look for the rest of the code.

Is this another ChatGPT attempt?

 
  1. 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. Stop using ChatGPT.
              Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum (2023)

  3. Do not post code that will not even compile.
              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.

  4. Hedging, grid trading, same as Martingale.
              Martingale, Hedging and Grid : MHG - General - MQL5 programming forum (2016)

    Martingale, guaranteed to blow your account eventually. If your strategy is not profitable without, it is definitely not profitable with.
              Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum (2015)

    Why it won't work:
              Calculate Loss from Lot Pips - MQL5 programming forum (2017)
              THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube (2020)

  5. if (OrdersTotal() > 0) return; // If there are open orders, do nothing

    Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
              PositionClose is not working - MQL5 programming forum (2020)
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
              Limit one open buy/sell position at a time - General - MQL5 programming forum (2022)

    You need one Magic Number for each symbol/timeframe/strategy.
         Trade current timeframe, one strategy, and filter by symbol requires one MN.
         If trading multiple timeframes, and filter by symbol requires use a range of MN (base plus timeframe).
              Why are MT5 ENUM_TIMEFRAMES strange? - General - MQL5 programming forum - Page 2 #11 (2020)