Im getting 2 errors one is ')' - unexpected end of program and the other is '{' - unbalanced parentheses

 

{

    // Get the current fast and slow moving averages

    double fastMA = iMA(_Symbol, 0, FastMA, 0, MODE_SMA, PRICE_CLOSE, 0);
    double slowMA = iMA(_Symbol, 0, SlowMA, 0, MODE_SMA, PRICE_CLOSE, 0);

    // Determine the trade type based on the moving averages
    if(fastMA > slowMA)
    {
        tradeType = 1; // Buy
    }
    else if(fastMA < slowMA)
    {
        tradeType = 0; // Sell
    }
    else
    {
        tradeType = -1; // No trade
    }

    // Place a buy order if the trade type is buy
    if(tradeType == 1 && lastBuyPrice == 0.0)
    {
        // Calculate the stop loss and take profit prices
        double stopLossPrice = Bid - StopLoss * _Point;
        double takeProfitPrice = Bid + TakeProfit * _Point;

        // Place the buy order
        lastBuyPrice = Ask;
        OrderSend(_Symbol, OP_BUY, LotSize, Ask, 10, stopLossPrice, takeProfitPrice, "Trend Following Buy", 0, 0, Green);
    }

    // Place a sell order if the trade type is sell
    if(tradeType == 0 && lastSellPrice == 0.0)
    {
        // Calculate the stop loss and take profit prices
        double stopLossPrice = Ask + StopLoss * _Point;
        double takeProfitPrice = Ask - TakeProfit * _Point;

        // Place the sell order
        lastSellPrice = Bid;
        OrderSend(_Symbol, OP_SELL, LotSize, Bid, 10, stopLossPrice, takeProfitPrice, "Trend Following Sell", 0, 0, Red);
    }

    // Modify the stop loss and take profit levels for the existing buy order
    if(tradeType == 1 && lastBuyPrice > 0.0)
    {
        // Calculate the new stop loss and take profit prices
        double stopLossPrice = Bid - StopLoss * _Point;
        double takeProfitPrice = lastBuyPrice + TakeProfit * _Point;

        // Modify the existing buy order
        OrderModify(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES), OrderOpenPrice(), stopLossPrice, takeProfitPrice,
void OnDeinit(const int reason)
  {}
  
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Is this your code, or did you generate it in ChatGPT?

If it is your code, then please take some time to learn the basics of how you have to define functions, how to define code blocks with and also how to balance parenthesis.

If it was generated code, then we are unable to help you, because any advice we give, you will not be able to understand or apply because you don't know how to code it yourself.

 

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.

 
        // Modify the existing buy order
        OrderModify(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES), OrderOpenPrice(), stopLossPrice, takeProfitPrice,
void OnDeinit(const int reason)
  {}
  1. OrderSelect does not return a ticket number, modify will never work.
  2. OrderModify incomplete, enclosing function incomplete.